Details
-
Type:
Bug
-
Status:
In Progress
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 2.0.2
-
Fix Version/s: None
-
Component/s: Serializer
-
Labels:None
-
Number of attachments :
Description
@JsonUnwrapped does not play nicely with polymorphic types.
After some debugging and digging through Jira issues, I did find Tatu's comment on JACKSON-132: "One caveat is that this will not work well with polymorphic types. But aside from that, things should just work."
So while it would be nice if polymorphic types did work, just making that caveat easier to find by updating the documentation, or by making the Exceptions thrown at runtime more descriptive, would go a long way towards helping other folks avoid the pain I just went through to get here
Here's an example not very helpful exception currently thrown when I try to serialize an Object in a @JsonUnwrapped property which has a @JsonTypeInfo annotation on it:
com.fasterxml.jackson.core.JsonGenerationException: Can not start an object, expecting field name
at com.fasterxml.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:412) ~[jackson-core-2.0.2.jar:na]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator._verifyValueWrite(UTF8JsonGenerator.java:1003) ~[jackson-core-2.0.2.jar:na]
at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeStartObject(UTF8JsonGenerator.java:347) ~[jackson-core-2.0.2.jar:na]
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeSerializer.writeTypePrefixForObject(AsPropertyTypeSerializer.java:48) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:416) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.impl.UnwrappingBeanPropertyWriter.serializeAsField(UnwrappingBeanPropertyWriter.java:102) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:504) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:117) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:94) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:150) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:108) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:567) ~[jackson-databind-2.0.2.jar:na]
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:461) ~[jackson-databind-2.0.2.jar:na]
Agreed – while fixing things is obviously preferable, improving error messages would be useful if that can't be done.
Unwrapping is one of features where implementations gets complicated enough that any bugs cropping up (on deserialization esp) tend to be antibiotic-resistant...