Skip to content

Deserialization fails when @JsonUnwrapped property contains an object with same property name #647

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

Closed
kulabun opened this issue Dec 11, 2014 · 1 comment
Milestone

Comments

@kulabun
Copy link
Contributor

kulabun commented Dec 11, 2014

private static class A {
    @JsonProperty("object")
    public Holder objectHolder;
}

private static class Holder {
    @JsonUnwrapped
    public B object;
}

private static class B {
    @JsonProperty("object")
    public String object;
}

On attemp to deserialize a stroke like {"object": {"object": "the value"}} we get an exception:

com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple >type, class com.fasterxml.jackson.failing.TestUnwrappedIssueNUMBER$B] from String value ('the >value'); no single-String constructor/factory method
at [Source: {"object": {"object": "the value"}}; line: 1, column: 13](through reference chain: >com.fasterxml.jackson.failing.A["object"]->com.fasterxml.jackson.failing.Holder["object"])
at >com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:788)
at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:277)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:284)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1140)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:135)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:126)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:529)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:106)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeWithUnwrapped(BeanDeserializer.java:511)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:274)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:124)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:529)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:106)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:242)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3335)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2375)

cowtowncoder added a commit that referenced this issue Dec 12, 2014
@cowtowncoder cowtowncoder added this to the 2.5.0 milestone Dec 12, 2014
@cowtowncoder
Copy link
Member

Looks like removal from PropertyMap solves this, with no new failures. I hope this means there are no nasty side-effects; but there's probably non-zero chance that something may need patching in future (for example, with JSON Schema handling).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants