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

Added new UNWRAP_SINGLE_VALUE_ARRAYS DeserializationFeature #384

Merged
merged 4 commits into from
Jan 10, 2014

Conversation

yinzara
Copy link
Contributor

@yinzara yinzara commented Jan 10, 2014

Fixes issue # 381

By default the new feature is disabled but if enabled (i.e. "objectMapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);"), any data bind to single element values (i.e. not a list or array) will allow the JSON to contain a single element array and will automatically unwrap that array value. See issue for more detailed information.

For example, let's say you had a class:

public class FooBean { public String bar; }

Without the feature enabled the deserializing following JSON into a FooBean would throw a JsonMappingException:
{ "bar" : [ "barValue" ] }

with the feature enabled, JSON processing would be successful and the FooBean would have the "bar" field set to "barValue".

However:
{ "bar" : [ "barValue", "barValue2" ] } (i.e. if the array contains more than a single element)
would still throw a JsonMappingException

All deserializers supported by jackson-databind have been updated to support the new feature.

Custom JsonDeserializer(s) developed externally to jackson-databind will need to be updated to read this feature's configured value to mimic identical behavior. However since the StdDeserializer and FromStringDeserializer have been updated, any custom deserializers that extend from those classes may function with the new feature without any modification.

Fixes issue FasterXML#381. Added new feature that determines whether it is
acceptable to coerce a single value array (in JSON) to the corresponding
value type.
Added fix to BeanDeserializerBase that when deserializing a bean, if the
UNWRAP_SINGLE_VALUE_ARRAYS feature is enabled, to unwrap a single
element array automatically.
Added test cases for single value arrays bean deserialization
* feature. If more than one value is found in the array, a JsonMappingException is thrown.
* <p>
* Feature is disabled by default
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add @since 2.4 so javadocs include that as a note?

@cowtowncoder
Copy link
Member

Whops. I did not immediatelly connect the dots wrt email address. Just processing the CLA. So never mind; will merge this PR soon.

cowtowncoder added a commit that referenced this pull request Jan 10, 2014
Added new UNWRAP_SINGLE_VALUE_ARRAYS DeserializationFeature
@cowtowncoder cowtowncoder merged commit d499f2e into FasterXML:master Jan 10, 2014
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