I have the following JAXB annotations on a field in a given POJO:
@XmlElements({ @XmlElement(name = "source", type = Pojo.class, required = true), @XmlElement(name = "otherSource", type = PojoExtended.class, required = true) })
private Pojo sourceItem;
The underlying POJOs (Pojo and PojoExtended) are serialized into values correctly, but the field name remains "sourceItem" even though there is an array of XmlElement definitions that should examine the type and use the "name" attribute of the annotation to determine the field name. In other words, an object of type Pojo should use "source" as the field name, and an object of type PojoExtended should use "otherSource" as the field name.
The POJO that houses the sourceItem field is not under my control, so I cannot change it.
My ObjectMapper is configured as follows:
return new ObjectMapper()
.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)
.registerModule(new JaxbAnnotationModule())
It looks like the findWrapperName method in JaxbAnnotationIntrospector can only handle the XmlElementWrapper annotation correctly (used in another POJO in the code base), but doesn't handle the polymorphic XmlElements/XmlElement annotations correctly.
I have the following JAXB annotations on a field in a given POJO:
The underlying POJOs (Pojo and PojoExtended) are serialized into values correctly, but the field name remains "sourceItem" even though there is an array of XmlElement definitions that should examine the type and use the "name" attribute of the annotation to determine the field name. In other words, an object of type Pojo should use "source" as the field name, and an object of type PojoExtended should use "otherSource" as the field name.
The POJO that houses the sourceItem field is not under my control, so I cannot change it.
My ObjectMapper is configured as follows:
It looks like the findWrapperName method in JaxbAnnotationIntrospector can only handle the XmlElementWrapper annotation correctly (used in another POJO in the code base), but doesn't handle the polymorphic XmlElements/XmlElement annotations correctly.