Add the ability to reset object properties to nil from JSON - #403
Conversation
…verting from JSON if optional and the json node contains "null"
|
Hi @pixel4, thanks for your work. This looks good and I think I will merge. I'm curious though, why was it necessary to add the |
|
Hi @tristanhimmelman, I'm glad you like it, thanks. We use this library all the time and this change is key for us. You need the flag |
|
|
||
| // check if a value exists for the current key | ||
| if nested == false { | ||
| currentValue = JSONDictionary[key] |
There was a problem hiding this comment.
This check is important for performance reasons. We previously didn't include it and the valueFor function became a performance bottleneck because it was being called so often without any need.
Can you please revert this
There was a problem hiding this comment.
absolutely.. I'll revert it and check my tests tonight.
|
One other thing that would be great to have before I merge this is a simple unit test that checks this functionality so that we ensure it is not broken down line with other updates. Would you be able to add one? |
|
yes.. I can add unit tests as well, np |
|
Hey @tristanhimmelman, I just reverted the change you asked and also added unit tests for this new functionality. I think we should also update the |
|
@pixel4 thanks for the updates. Looks great! I agree about updating the minor version. I will take care of that when I release. |
|
Thanks @tristanhimmelman |
The current version has a problem that makes it impossible for us to in our app in production, so we did all necessary modifications and now I'm requesting this pull request here and it may help other as well.
We needed the ability to reset some fields to
nilwhen updating existing objects with new JSON data. We do that by setting the desired field in the JSON string with"null"value and we expect that ObjectMapper will set that field tonilwhen mapping to the object since the JSON contains the field in its body.Example:
Imagine a
Playerclass like this:Initialized:
Update name and remove team