Allow optional primitives when FAIL_ON_NULL_FOR_PRIMITIVES=true #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thecreateFromObjectWith()
method and was always executed. This commit reorganizes that method to remove thebuffer.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 neededbuffer.getParameter()
is used to get only that specific property's value.