diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 8a4404e8f..66f733d15 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -6,6 +6,9 @@ Project: jackson-dataformat-xml 2.11.1 (not yet released) +#86: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName + matches `@JacksonXmlRootElement` localName + (reported by Eric S) #294: XML parser error with nested same element names (reported by Alexei V) #393: `MismatchedInputException` for nested repeating element name in `List` diff --git a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java index 10846e771..1334ff0d9 100644 --- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java +++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java @@ -324,10 +324,15 @@ public void addVirtualWrapping(Set namesToWrap) //System.out.println("addVirtualWrapping("+namesToWrap+")"); // 17-Sep-2012, tatu: Not 100% sure why, but this is necessary to avoid // problems with Lists-in-Lists properties - String name = _xmlTokens.getLocalName(); - if (name != null && namesToWrap.contains(name)) { + // 12-May-2020, tatu: But as per [dataformat-xml#86] NOT for root element + // (would still like to know why work-around needed ever, but...) + if (_parsingContext.inObject() + && !_parsingContext.getParent().inRoot()) { + String name = _xmlTokens.getLocalName(); + if ((name != null) && namesToWrap.contains(name)) { //System.out.println("REPEAT from addVirtualWrapping()"); - _xmlTokens.repeatStartElement(); + _xmlTokens.repeatStartElement(); + } } _parsingContext.setNamesToWrap(namesToWrap); } diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java index 862809994..ac1f80169 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Objects; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.dataformat.xml.XmlMapper; @@ -39,7 +40,8 @@ public boolean equals(final Object other) { } final Issue86 otherIssue86 = (Issue86) other; - return otherIssue86.id.equals(id) && otherIssue86.children.equals(children); + return Objects.equals(id, otherIssue86.id) + && Objects.equals(children, otherIssue86.children); } }