Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ability to ignore a field during serialization #148

Merged
merged 4 commits into from
Feb 12, 2017

Conversation

vladimir-bebeshko
Copy link
Contributor

Currently returning nil from the field's reverse block causes an exception
because of using setObject: syntax for NSDictionary (can't have nil
in collections). This makes impossible to ignore a field in the
serialization representation:

[mapping mapKeyPath:@"ip" toProperty:@"ipAddress"
     withValueBlock:^id(NSString *key, id value) {
    return value;
} reverseBlock:^id(id value) {
    return nil; //causes an exception later
}];

This fix makes the code above work as expected: the keyPath will be
ignored during [EKSerializer serializeObject:self withMapping:mapping];

Now returning nil from the field's reverse block causes an exception
because of using `setObject:` syntax for NSDictionary (can't have nil
in collections). This makes impossible to ignore a field in the
serialization representation:

```
[mapping mapKeyPath:@"ip" toProperty:@"ipAddress"
     withValueBlock:^id(NSString *key, id value) {
    return value;
} reverseBlock:^id(id value) {
    return nil; //causes an exception later
}];
```
This fix makes the code above work as expected: the keyPath will be
ignored during `[EKSerializer serializeObject:self
withMapping:mapping];`
@DenTelezhkin
Copy link
Collaborator

Thanks!

Can i ask you to write unit test for this case?

Vladimir Bebeshko added 3 commits February 9, 2017 15:57
Contexts named
 * using EKMappingBlocks
 * using mapping blocks with nil value

weren't executing beause the `should` clauses inside of them were
written outside of the `specify` blocks.
Fixed.
Had to modify "when male" context as well as I moved its `beforeEach`
block up.
@vladimir-bebeshko
Copy link
Contributor Author

@DenHeadless done. Also made some fixes for test that weren't executing because of incorrect Kiwi syntax. +a bit of cosmetics :-)

@DenTelezhkin DenTelezhkin merged commit c07f315 into lucasmedeirosleite:master Feb 12, 2017
@DenTelezhkin
Copy link
Collaborator

Thanks again!

I've cut 0.20.1 release with these changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants