-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Provided TypeReference doesn't enable deserialization of an object with generic constructor #254
Comments
jackson-databind version 2.2.2 |
Actually even using javaType it throws the same error: JavaType javaType = mapper.getTypeFactory().constructParametricType(AgentResponse.class, Map.class);
mapper.readValue(out, javaType); |
SOLVED: I didn't know that I have to use @JsonCreator and @JsonProperty("result") annotations ... I was debugging the jackson stack all the way down and I saw it found the constructor arguments, so I thought it was the generics problem. In fact the real problem was that jackson couldn't know the constructor argument names cause JVM doesn't provide it. Damn I should have try that without generics first... |
Correct: Except that if you want to get by without second part, you can try to use this module: https://github.com/FasterXML/jackson-module-paranamer which uses |
Model:
Input Json:
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.fg.mail.smtp.AgentResponse<java.util.Map<java.lang.String,java.lang.Integer>>]: can not instantiate from JSON object (need to add/enable type information?)
at [Source: java.io.InputStreamReader@4f2d26d2; line: 1, column: 2]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:984)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:276)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2064)
The text was updated successfully, but these errors were encountered: