Type: New Feature
Resolution: Won't Fix
Affects Version/s: None
Fix Version/s: None
Number of attachments :
When deserializing, it's common for folks to need to unwrap single-component JSON arrays, for downstream handling of the component value. If a feature to enable automagic unwrapping of such arrays were provided, then folks could code mapping solutions as simply as
Such configuration could also be available through an annotation. The annotation could be applied to specific properties, or to a class (to effectively apply the annotation to all properties defined in the class).
While the argument that this code
sufficiently indicates the author's intentions and provides enough configuration information that ObjectMapper could know what to do – to unwrap  to just 42 – I cannot think of any significant benefit to enabling such unwrapping by default. The obvious possible detriment would be breaking existing legacy code.
For consistency, this feature should be applicable to single-component JSON arrays of any primitive, null, object, or array type. So, all of the following examples would work.
The following attempted use of this feature on a JSON array with more than one component should result in a JsonMappingException thrown by the ObjectMapper. (Though, the current error message that "Can not deserialize instance of int out of START_ARRAY token" could be enhanced to recognize the attempt to auto-unwrap the JSON array as if it were a single-component array.)
For completeness, such a feature could have a serialization counterpart: to wrap a single value into a single-component JSON array.