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 the ability to reset object properties to nil
from JSON
#403
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 |
@@ -62,13 +63,8 @@ public final class Map { | |||
currentKey = key | |||
keyIsNested = nested | |||
|
|||
// check if a value exists for the current key | |||
if nested == false { | |||
currentValue = JSONDictionary[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
nil
when 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 tonil
when mapping to the object since the JSON contains the field in its body.Example:
Imagine a
Player
class like this:Initialized:
Update name and remove team