FasterXML / FasterXML/jackson-modules-base
JAXB Module not handling polymorphic field name serialization when field annotated with XmlElements
- Dominant language
- Java
- Stars
- 180
- Forks
- 80
- Avg merge
- 3h 26m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.