Skip to content

Commit 5af8b0c

Browse files
committed
Fix #86
1 parent e6e5a5f commit 5af8b0c

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

release-notes/CREDITS-2.x

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ Alexei Volkov (softkot@github)
6666
* Reported #294: XML parser error with nested same element names
6767
(2.11.1)
6868

69+
Eric Schoonover (spoon16@github)
70+
71+
* Reported #86: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName
72+
matches `@JacksonXmlRootElement` localName
73+
(2.12.0)
74+
6975
Joseph Petersen (jetersen@github)
7076

7177
* Reported #273: Input mismatch with case-insensitive properties

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-dataformat-xml
66

77
2.12.0 (not yet released)
88

9+
#86: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName
10+
matches `@JacksonXmlRootElement` localName
11+
(reported by Eric S)
912
#273: Input mismatch with case-insensitive properties
1013
(reported by Joseph P)
1114
#318: XMLMapper fails to deserialize null (POJO reference) from blank tag

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,23 @@ public XMLStreamReader getStaxReader() {
322322
*/
323323
public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive)
324324
{
325-
//System.out.printf("addVirtualWrapping(%s) [case-insensitive? %s]\n", namesToWrap0, caseInsensitive);
325+
//System.out.printf("addVirtualWrapping(%s) at '%s' [case-insensitive? %s]\n", namesToWrap0, _parsingContext.pathAsPointer(), caseInsensitive);
326326

327327
final Set<String> namesToWrap = caseInsensitive
328328
? CaseInsensitiveNameSet.construct(namesToWrap0)
329329
: namesToWrap0;
330330

331-
// 17-Sep-2012, tatu: Not 100% sure why, but this is necessary to avoid
331+
// 17-Sep-2012, tatu: Not 100% sure why, but this is necessary to avoid
332332
// problems with Lists-in-Lists properties
333-
String name = _xmlTokens.getLocalName();
334-
if ((name != null) && namesToWrap.contains(name)) {
333+
// 12-May-2020, tatu: But as per [dataformat-xml#86] NOT for root element
334+
// (would still like to know why work-around needed ever, but...)
335+
if (_parsingContext.inObject()
336+
&& !_parsingContext.getParent().inRoot()) {
337+
String name = _xmlTokens.getLocalName();
338+
if ((name != null) && namesToWrap.contains(name)) {
335339
//System.out.println("REPEAT from addVirtualWrapping()");
336-
_xmlTokens.repeatStartElement();
340+
_xmlTokens.repeatStartElement();
341+
}
337342
}
338343
_parsingContext.setNamesToWrap(namesToWrap);
339344
}

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestUnwrappedDeserIssue86.java renamed to src/test/java/com/fasterxml/jackson/dataformat/xml/lists/NestedUnwrappedLists86Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.dataformat.xml.failing;
1+
package com.fasterxml.jackson.dataformat.xml.lists;
22

33
import java.util.Arrays;
44
import java.util.List;
@@ -11,7 +11,7 @@
1111
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
1212
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
1313

14-
public class TestUnwrappedDeserIssue86 extends XmlTestBase
14+
public class NestedUnwrappedLists86Test extends XmlTestBase
1515
{
1616
@JacksonXmlRootElement(localName = "test")
1717
public static class Issue86 {

0 commit comments

Comments
 (0)