Two wrapped lists with items of same name conflict when XML Annotations and both JaxbAnnotationModule and JakartaXmlBindAnnotationModule are used
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start by tracing how the XML module combines annotations from JaxbAnnotationModule and JakartaXmlBindAnnotationModule when discovering wrapped list properties. Reproduce the reported failure with the supplied Wrapper record and both modules, then compare it with the Jackson XML annotations case. Done means serialization succeeds for both lists with the same @XmlElement name when both annotation modules are registered.
Written by the indexing model from the issue text.
Description
This seems a very specific case left after https://github.com/FasterXML/jackson-dataformat-xml/issues/192 was solved.
Using Jackson 3.3.0, this:
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import org.junit.jupiter.api.Test;
import tools.jackson.dataformat.xml.XmlMapper;
import tools.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule;
import tools.jackson.module.jaxb.JaxbAnnotationModule;
class NestedListsWithObjectsWithJaxbAndJakartaModules {
record Wrapper(@XmlElementWrapper(name = "ones") @XmlElement(name = "name") List<String> ones,
@XmlElementWrapper(name = "twos") @XmlElement(name = "name") List<String> twos) {
}
@Test
void shouldHandleNestedListsWithObjectsWithJaxbAndJakartaModules() {
Wrapper wrapper = new Wrapper(List.of("item0"), List.of("item1"));
XmlMapper.builder()
.addModules(new JaxbAnnotationModule())
.addModule(new JakartaXmlBindAnnotationModule())
.build()
.writeValueAsString(wrapper);
}
}
fails with:
tools.jackson.databind.exc.InvalidDefinitionException: Invalid type definition for type `test.NestedListsWithObjectsWithJaxbAndJakartaModules$Wrapper`: Conflicting getter definitions for property "name": test.NestedListsWithObjectsWithJaxbAndJakartaModules$Wrapper#ones() vs test.NestedListsWithObjectsWithJaxbAndJakartaModules$Wrapper#twos()
at [No location information]
at tools.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:75)
at tools.jackson.databind.SerializationContext.reportBadTypeDefinition(SerializationContext.java:1366)
at tools.jackson.databind.DatabindContext.reportBadTypeDefinition(DatabindContext.java:712)
at tools.jackson.databind.SerializationContext._createAndCacheUntypedSerializer(SerializationContext.java:1026)
at tools.jackson.databind.SerializationContext.findValueSerializer(SerializationContext.java:829)
at tools.jackson.databind.SerializationContext.findTypedValueSerializer(SerializationContext.java:625)
at tools.jackson.dataformat.xml.ser.XmlSerializationContext.serializeValue(XmlSerializationContext.java:80)
at tools.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:1921)
at tools.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:1857)
at test.NestedListsWithObjectsWithJaxbAndJakartaModules.shouldHandleNestedListsWithObjectsWithJaxbAndJakartaModules(NestedListsWithObjectsWithJaxbAndJakartaModules.java:28)
Suppressed: tools.jackson.core.exc.StreamWriteException: Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document).
at [No location information]
at tools.jackson.dataformat.xml.util.StaxUtil.throwAsWriteException(StaxUtil.java:29)
at tools.jackson.dataformat.xml.ser.ToXmlGenerator._closeInput(ToXmlGenerator.java:1862)
at tools.jackson.core.base.GeneratorBase.close(GeneratorBase.java:335)
at tools.jackson.databind.util.ClassUtil.closeOnFailAndThrowAsJacksonE(ClassUtil.java:413)
at tools.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:1923)
... 2 more
Caused by: com.ctc.wstx.exc.WstxOutputException: Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document).
at com.ctc.wstx.sw.BaseStreamWriter.throwOutputError(BaseStreamWriter.java:1618)
at com.ctc.wstx.sw.BaseStreamWriter.reportNwfStructure(BaseStreamWriter.java:1653)
at com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1457)
at com.ctc.wstx.sw.BaseStreamWriter.closeCompletely(BaseStreamWriter.java:962)
at tools.jackson.dataformat.xml.ser.ToXmlGenerator._closeInput(ToXmlGenerator.java:1857)
... 5 more
This only happens if both JaxbAnnotationModule and JakartaXmlBindAnnotationModule are used. And only if @XmlElementWrapper and @XmlElement (does not matter if from the javax or jakarta package) are used. It works with @JacksonXmlElementWrapper and @JacksonXmlProperty.
By the way: Thank you very much for providing Jackson!
- Dominant language
- Java
- Stars
- 636
- Forks
- 250
- Avg merge
- 7h 10m
- Merged PRs (30d)
- 8
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FasterXML/jackson-dataformat-xml
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
FasterXML/jackson-dataformat-xml#931 · 3 comments ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only elementPossibly taken @arimu1 claimed this 89 days ago. Opento-evaluate
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
3.x
Difficulty 4/5 3-5 days Newbie friendliness 25/100
FasterXML/jackson-dataformat-xml#787 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FasterXML/jackson-dataformat-xml#712 · 3 comments ·
All issues in FasterXML/jackson-dataformat-xml
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
johanhaleby/occurrent#1505 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
FasterXML/jackson-databind#6443 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
finos/fluxnova-bpm-platform#387 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100