@JsonAnySetter with @JsonUnwrapped: deserialization fails with arrays
See original GitHub issueMy application makes heavy use of the @JsonAnySetter/Getter annotations which is currently throwing an exception when deserializing an JSON array of strings as a property value:
Can not deserialize instance of java.lang.Object out of END_ARRAY token at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@7a5d231e; line: 22, column: 5] (through reference chain: com.mycorp.core.web.rest.dto.ItemDTO["ZoomLinks"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:569)
at com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer.deserialize(UntypedObjectDeserializer.java:90)
at com.fasterxml.jackson.databind.deser.SettableAnyProperty.deserialize(SettableAnyProperty.java:98)
at com.fasterxml.jackson.databind.deser.SettableAnyProperty.deserializeAndSet(SettableAnyProperty.java:88)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeWithUnwrapped(BeanDeserializer.java:515)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:271)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1179)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:635)
Here is the Java code:
public void addProperty(String key, Object value) {
if (props == null)
{ props = new HashMap<String, Object>(); }
props.put(key, value);
}
@JsonAnyGetter
public Map<String, Object> getProperties()
{ return props; }
and here is some sample JSON that will fail:
{ "_type" : "IST",
"_spacename" : "Foo Models",
"_name" : "BLAH-New",
"_description" : "namespace.name: X THIN FIR.DR-WD12-New",
"ZoomLinks": [ "foofoofoofoo", "barbarbarbar" ] }
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
JsonAnySetter with @JsonUnwrapped: deserialization fails ...
My application makes heavy use of the @JsonAnySetter/Getter annotations which is currently throwing an exception when deserializing an JSON ...
Read more >java - What's the Jackson deserialization equivalent of ...
For those who googled here like me, trying to resolve issue when deserializing unwrapepd Map , there is a solution with @JsonAnySetter :...
Read more >Jackson JSON - Using @JsonUnwrapped to serialize ...
JsonUnwrapped is used to indicate that a property should be serialized unwrapped, i.e. the target property will not be serialized as JSON ...
Read more >Jackson Annotation Examples - Baeldung
On deserialization, the properties from JSON will simply be added to the map. First, we'll use @JsonAnySetter to deserialize the entity ...
Read more >Jackson Annotations for JSON - Spring Framework Guru
@JsonUnwrapped. The. @JsonUnwrapped. @JsonUnwrapped annotation unwraps the values during serialization and deserialization. It helps in rendering the values ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cowtowncoder It seems JsonAnySetter and JsonUnwrapped can work together in 2.9.0-SNAPSHOT but not in 2.8.6. I have added one test case here: https://github.com/borball/jackson-test/blob/master/src/test/java/com/fasterxml/jackson/test/JacksonTest.java#L15-L19 With 2.9.0-SNAPSHOT I can successfully get bean object refundQuery but with 2.8.6, it is null.
I think that the way things are implemented duplicates would always have occurred.
Later issue #1811 cover the problem: I hope this can be resolved in 3.0.