Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

JsonCreator deser with single-String-argument constructor fails #28

Closed
sgmiller opened this issue Jun 25, 2013 · 4 comments
Closed

JsonCreator deser with single-String-argument constructor fails #28

sgmiller opened this issue Jun 25, 2013 · 4 comments
Milestone

Comments

@sgmiller
Copy link

I don't have a simple test case for this, but the case seems simple enough to me. I have a containing class with a public field of the contained class, basically this:

public class Outer {

public Inner inner;

}

public class Inner {

@JsonCreator
public Inner(String value) {
...
}

@JsonValue
public String toString() {
...}
}
}

When deserializing an object containing Outer, I get the following exception, only if afterburner is enabled. I'm using Smile as the dataformat. I've modified the object references to protect the innocent:

com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type java.lang.String from String value; no single-String constructor/factory method (through reference chain: xxxx["xxxx"]->com.beecavegames.xxxx["inner"])
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createFromStringFallbacks(StdValueInstantiator.java:428) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:299) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1056) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:136) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:123) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SettableObjectFieldProperty.deserializeAndSet(SettableObjectFieldProperty.java:53) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserializeFromObject(SuperSonicBeanDeserializer.java:192) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:230) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:207) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SettableObjectFieldProperty.deserializeAndSet(SettableObjectFieldProperty.java:53) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:206) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserializeFromObject(SuperSonicBeanDeserializer.java:205) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:157) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:123) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:113) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:82) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:894) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:393) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:317) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:26) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SettableObjectMethodProperty.deserializeAndSet(SettableObjectMethodProperty.java:53) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.module.afterburner.deser.SuperSonicBeanDeserializer.deserializeFromObject(SuperSonicBeanDeserializer.java:209) ~[jackson-module-afterburner-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888) ~[jackson-databind-2.2.2.jar:2.2.2]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2103) ~[jackson-databind-2.2.2.jar:2.2.2]

@cowtowncoder
Copy link
Member

Is inner class not a static class? And if so, why not? Not sure if that is relevant here, but just asking since handling of non-static inner classes is quite specialized; and there are a few existing tests for some common @JsonCreator usage patterns.

@cowtowncoder
Copy link
Member

Looks like I may need a test case: simple test with static inner class works as expected. Without static I get different error.

@cowtowncoder cowtowncoder changed the title JsonCreator deser fails JsonCreator deser with single-String-argument constructor fails Apr 9, 2014
cowtowncoder added a commit that referenced this issue Apr 9, 2014
cowtowncoder added a commit that referenced this issue Apr 9, 2014
@cowtowncoder
Copy link
Member

Actually, I hit this bug myself -- at least I think it is the same, as the symptom is the same.

@cowtowncoder cowtowncoder added this to the 2.3.3 milestone Apr 9, 2014
@cowtowncoder
Copy link
Member

FWIW, I hit this with DropWizard-0.7 configs, having a bean that uses single-arg constructor, in a list. Need to get 2.3.3 released soon.

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

No branches or pull requests

2 participants