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

Allow optional primitives when FAIL_ON_NULL_FOR_PRIMITIVES=true #41

Merged
merged 1 commit into from
Oct 25, 2016

Conversation

kpdonn
Copy link
Contributor

@kpdonn kpdonn commented Oct 12, 2016

Use case is to enable FAIL_ON_NULL_FOR_PRIMITIVES so that non-nullable and non-optional primitive fields do not default to their platform zero value when they are excluded from the json but instead raise a json mapping exception. However enabling that feature also caused optional primitive fields with default values specified to throw the same exception.

The problem was the exception for null primitives was thrown inside the buffer.getParameters(props) call which was at the beginning of the createFromObjectWith() method and was always executed. This commit reorganizes that method to remove the buffer.getParameters() call and instead first check each property to see if it is missing in the json and optional in which case the buffer value is not needed. Otherwise if the buffer value is needed buffer.getParameter() is used to get only that specific property's value.

Use case is to enable FAIL_ON_NULL_FOR_PRIMITIVES so that non-nullable
and non-optional primitive fields do not default to their platform zero
value when they are excluded from the json but instead raise a json
mapping exception. However enabling that feature also caused optional
primitive fields with default values specified to throw the same
exception.

The problem was the exception for null primitives was thrown inside the
buffer.getParameters(props) call which was at the beginning of the
createFromObjectWith() method and was always executed. This commit
reorganizes that method to remove the buffer.getParameters() call and
instead first check each property to see if it is missing in the json
and optional in which case the buffer value is not needed. Otherwise
if the buffer value is needed buffer.getParameter() is used to get only
that specific property's value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants