-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
only works for POJOs, Maps
#994
Comments
BeanDeserializerBase.java (L1239) if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY && ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
return null;
}
final Object value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array");
}
return value;
} seems to have the right implementation in method deserializeFromArray(...), if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
// CHECK MISSING HERE
final String parsed = _parseString(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value but there was more than a single value in the array");
}
return parsed;
} if (curr == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
// CHECK MISSING HERE
final String parsed = _parseString(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value but there was more than a single value in the array");
}
return parsed;
} do not check for if (token == JsonToken.END_ARRAY && ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
return null;
} in a very similar situation. This occurs probably for every other primitive type. |
Problem does occur with target types:
Problem does NOT occur with target types:
( Does not work for other modules like e.g. |
Thank you for thorough investigation. Yes, sounds like As to whether empty array should result in |
Thank you for the confirmation.
Since both versions are currently bugged (1.) or not implemented (2.), my current workaround is to intercept and preprocess the JSON file, replacing every occurence of |
Ok: just to make sure, |
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
)
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
)DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
only works for POJOs, Maps
Implemented full support in 2.9.0, added tests; should also be much easier to support from datatype libs as well (helper methods in |
Hi, Enabling "DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS" does not help for arrays having more than one value. Do we have a workaround for this? While trying to deserialize - Unexpected token (VALUE_NUMBER_INT), expected END_ARRAY: Attempted to unwrap 'java.lang.String' value from an array (with Thanks for helping. |
@Arunkumarpandy1984 Assuming |
Documentation of
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
only mentiones exceptional behavior for more than one value in the array ("If more than one value is found in the array, a JsonMappingException is thrown."). But trying to parse{ "value" : [] }
withvalue
asString
produces the following Stacktrace: (Parsing asnull
might be expected instead)This shouldn't be problematic when using
DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT
, but it does not take precedence overDeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS
(bug?) and still gives me the error from above!Are there any workarounds? I still need to map single element arrays, that sometimes appear to be empty. (I am using version 2.5.1, tested also 2.6.0: same behavior)
The text was updated successfully, but these errors were encountered: