Skip to content

@JsonAnySetter with @JsonUnwrapped: deserialization fails with arrays #349

@hdave

Description

@hdave

My 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" ] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions