-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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" : [] }
with value
as String
produces the following Stacktrace: (Parsing as null
might be expected instead)
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of END_ARRAY token
at [Source: { "value" : [] }; line: 1, column: 14] (through reference chain: app.Data["value"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:835)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseString(StdDeserializer.java:809)
at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:35)
at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:12)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:523)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.findDeserializeAndSet(BeanPropertyMap.java:285)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:248)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:136)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2578)
at app.MainKt.main(Main.kt:23)
data class Data(var value : String? = null) // valid example container in Kotlin
This shouldn't be problematic when using DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT
, but it does not take precedence over DeserializationFeature.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)