You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The builder deserailizer throws the "Build method has bad return type, not compatible with POJO type” exception if the build method return type is a super type of the POJO type. Here is a complete example:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Build method 'stackoverflow.JacksonBuilder$Foo$Builder#build(0 params) has bad return type (stackoverflow.JacksonBuilder$FooInterface), not compatible with POJO type (stackoverflow.JacksonBuilder$Foo)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:270)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:245)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:143)
at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:406)
at com.fasterxml.jackson.databind.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:176)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:110)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:95)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:131)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:42)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2578)
at stackoverflow.JacksonBuilder.main(JacksonBuilder.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.IllegalArgumentException: Build method 'stackoverflow.JacksonBuilder$Foo$Builder#build(0 params) has bad return type (stackoverflow.JacksonBuilder$FooInterface), not compatible with POJO type (stackoverflow.JacksonBuilder$Foo)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder.buildBuilderBased(BeanDeserializerBuilder.java:378)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBuilderBasedDeserializer(BeanDeserializerFactory.java:297)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBuilderBasedDeserializer(BeanDeserializerFactory.java:155)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:351)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:265)
... 16 more
Based on the following stack overflow question: http://stackoverflow.com/questions/29724859/jackson-deserialization-with-builder-pattern-build-method-has-bad-return-type
The builder deserailizer throws the "Build method has bad return type, not compatible with POJO type” exception if the build method return type is a super type of the POJO type. Here is a complete example:
Output:
It seems that the condition at
jackson-databind/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java
Line 377 in f757415
to allow
rawBuildType
be a super type of thevalueType
.The text was updated successfully, but these errors were encountered: