diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index bc33fdec4..0142c659d 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -66,6 +66,12 @@ Alexei Volkov (softkot@github) * Reported #294: XML parser error with nested same element names (2.11.1) +Eric Schoonover (spoon16@github) + +* Reported #86: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName + matches `@JacksonXmlRootElement` localName + (2.12.0) + Joseph Petersen (jetersen@github) * Reported #273: Input mismatch with case-insensitive properties diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index b89348f58..59e0190e1 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -6,6 +6,9 @@ Project: jackson-dataformat-xml 2.12.0 (not yet released) +#86: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName + matches `@JacksonXmlRootElement` localName + (reported by Eric S) #273: Input mismatch with case-insensitive properties (reported by Joseph P) #318: XMLMapper fails to deserialize null (POJO reference) from blank tag 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 67345d279..9ea617139 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 @@ -322,18 +322,23 @@ public XMLStreamReader getStaxReader() { */ public void addVirtualWrapping(Set namesToWrap0, boolean caseInsensitive) { -//System.out.printf("addVirtualWrapping(%s) [case-insensitive? %s]\n", namesToWrap0, caseInsensitive); +//System.out.printf("addVirtualWrapping(%s) at '%s' [case-insensitive? %s]\n", namesToWrap0, _parsingContext.pathAsPointer(), caseInsensitive); final Set namesToWrap = caseInsensitive ? CaseInsensitiveNameSet.construct(namesToWrap0) : namesToWrap0; -// 17-Sep-2012, tatu: Not 100% sure why, but this is necessary to avoid + // 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/lists/NestedUnwrappedLists86Test.java similarity index 96% rename from src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java rename to src/test/java/com/fasterxml/jackson/dataformat/xml/lists/NestedUnwrappedLists86Test.java index ded692bcc..1c14d6c03 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/lists/NestedUnwrappedLists86Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.dataformat.xml.failing; +package com.fasterxml.jackson.dataformat.xml.lists; import java.util.Arrays; import java.util.List; @@ -11,7 +11,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -public class TestUnwrappedDeserIssue86 extends XmlTestBase +public class NestedUnwrappedLists86Test extends XmlTestBase { @JacksonXmlRootElement(localName = "test") public static class Issue86 {