Skip to content

Commit ee5ce93

Browse files
committed
Merge branch '2.11' into 2.12
2 parents 1108ca2 + 35f7fcf commit ee5ce93

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Project: jackson-dataformat-xml
2323
(reported by Alexei V)
2424
#393: `MismatchedInputException` for nested repeating element name in `List`
2525
(reported by kaizenHorse@github)
26+
#399: Can not deserialize unwrapped list when `@JacksonXmlProperty` localName matches
27+
the parent's localName
28+
(reported by sandboxgod@github)
2629
2730
2.11.0 (26-Apr-2020)
2831

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive
332332
// problems with Lists-in-Lists properties
333333
// 12-May-2020, tatu: But as per [dataformat-xml#86] NOT for root element
334334
// (would still like to know why work-around needed ever, but...)
335-
if (_parsingContext.inObject()
335+
if (!_parsingContext.inRoot()
336336
&& !_parsingContext.getParent().inRoot()) {
337337
String name = _xmlTokens.getLocalName();
338338
if ((name != null) && namesToWrap.contains(name)) {
339-
//System.out.println("REPEAT from addVirtualWrapping()");
339+
//System.out.println("REPEAT from addVirtualWrapping() for '"+name+"'");
340340
_xmlTokens.repeatStartElement();
341341
}
342342
}

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

+16-8
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,33 @@ public int next() throws XMLStreamException
170170
int n = next0();
171171
switch (n) {
172172
case XML_START_ELEMENT:
173-
System.out.println(" XmlTolenStream.next(): XML_START_ELEMENT '"+_localName+"'");
173+
System.out.printf(" XmlTokenStream.next(): XML_START_ELEMENT '%s' %s\n", _localName, _loc());
174174
break;
175175
case XML_END_ELEMENT:
176-
System.out.println(" XmlTolenStream.next(): XML_END_ELEMENT '"+_localName+"'");
176+
System.out.printf(" XmlTokenStream.next(): XML_END_ELEMENT '%s' %s\n", _localName, _loc());
177177
break;
178178
case XML_ATTRIBUTE_NAME:
179-
System.out.println(" XmlTolenStream.next(): XML_ATTRIBUTE_NAME '"+_localName+"'");
179+
System.out.printf(" XmlTokenStream.next(): XML_ATTRIBUTE_NAME '%s' %s\n", _localName, _loc());
180180
break;
181181
case XML_ATTRIBUTE_VALUE:
182-
System.out.println(" XmlTolenStream.next(): XML_ATTRIBUTE_VALUE '"+_textValue+"'");
182+
System.out.printf(" XmlTokenStream.next(): XML_ATTRIBUTE_VALUE '%s' %s\n", _textValue, _loc());
183183
break;
184184
case XML_TEXT:
185-
System.out.println(" XmlTolenStream.next(): XML_TEXT '"+_textValue+"'");
185+
System.out.printf(" XmlTokenStream.next(): XML_TEXT '%s' %s\n", _textValue, _loc());
186186
break;
187187
case XML_END:
188-
System.out.println(" XmlTolenStream.next(): XML_END");
188+
System.out.printf(" XmlTokenStream.next(): XML_END %s\n", _loc());
189189
break;
190190
default:
191191
throw new IllegalStateException();
192192
}
193193
return n;
194194
}
195+
196+
private String _loc() {
197+
JsonLocation loc = getCurrentLocation();
198+
return String.format("[line: %d, column: %d]", loc.getLineNr(), loc.getColumnNr());
199+
}
195200
*/
196201

197202
// public int next0() throws XMLStreamException
@@ -252,14 +257,17 @@ public JsonLocation getTokenLocation() {
252257
/**
253258
* Method used to add virtual wrapping, which just duplicates START_ELEMENT
254259
* stream points to, and its matching closing element.
255-
*
256-
* @since 2.1
257260
*/
258261
protected void repeatStartElement()
259262
{
260263
//System.out.println(" -> repeatStartElement for "+_localName+", _currentWrapper was: "+_currentWrapper);
261264
// sanity check: can only be used when just returned START_ELEMENT:
262265
if (_currentState != XML_START_ELEMENT) {
266+
// 14-May-2020, tatu: Looks like we DO end up here with empty Lists; if so,
267+
// should NOT actually wrap.
268+
if (_currentState == XML_END_ELEMENT) {
269+
return;
270+
}
263271
throw new IllegalStateException("Current state not XML_START_ELEMENT ("
264272
+XML_START_ELEMENT+") but "+_currentState);
265273
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
6+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
7+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
8+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
9+
10+
public class ListDeser399Test extends XmlTestBase
11+
{
12+
static class Main {
13+
@JacksonXmlProperty(localName = "test")
14+
@JacksonXmlElementWrapper(useWrapping = false)
15+
List<Test> list = new ArrayList<Test>();
16+
}
17+
18+
static class Test {
19+
@JacksonXmlProperty(localName = "test")
20+
@JacksonXmlElementWrapper(useWrapping = false)
21+
List<Test> list = new ArrayList<Test>();
22+
}
23+
24+
private final XmlMapper MAPPER = newMapper();
25+
26+
public void testIssue399() throws Exception {
27+
final String XML =
28+
"<Main>\n" +
29+
" <test>\n" +
30+
" <test>\n" +
31+
" <test>\n" +
32+
" </test>\n" +
33+
//" <test>\n" +
34+
//" </test>\n" +
35+
" </test>\n" +
36+
" </test>\n" +
37+
" <test>\n" +
38+
" </test>\n" +
39+
"</Main>";
40+
Main main = MAPPER.readValue(XML, Main.class);
41+
assertNotNull(main);
42+
assertNotNull(main.list);
43+
assertEquals(2, main.list.size());
44+
assertNotNull(main.list.get(0));
45+
assertNotNull(main.list.get(0).list);
46+
assertEquals(1, main.list.get(0).list.size());
47+
assertNotNull(main.list.get(1));
48+
}
49+
}

0 commit comments

Comments
 (0)