Skip to content

Commit d9738d9

Browse files
committed
Fix #469 (yet another issue with unwrapped lists)
1 parent 64532a1 commit d9738d9

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-xml
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.12.4 (not yet released)
8+
9+
#469: Empty tags cause incorrect deserialization of unwrapped lists
10+
(reported by jackson-code1@github)
11+
712
2.12.3 (12-Apr-2021)
813

914
#456: Fix JsonAlias with unwrapped lists

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.*;
55

66
import com.fasterxml.jackson.core.JsonParser;
7+
import com.fasterxml.jackson.core.JsonToken;
78
import com.fasterxml.jackson.core.util.JsonParserDelegate;
89
import com.fasterxml.jackson.databind.*;
910
import com.fasterxml.jackson.databind.deser.*;
@@ -154,7 +155,14 @@ protected final void _configureParser(JsonParser p) throws IOException
154155
p = ((JsonParserDelegate) p).delegate();
155156
}
156157
if (p instanceof FromXmlParser) {
157-
((FromXmlParser) p).addVirtualWrapping(_namesToWrap, _caseInsensitive);
158+
// 03-May-2021, tatu: as per [dataformat-xml#469] there are special
159+
// cases where we get String token to represent XML empty element.
160+
// If so, need to refrain from adding wrapping as that would
161+
// override parent settings
162+
JsonToken t = p.currentToken();
163+
if (t == JsonToken.START_OBJECT || t == JsonToken.START_ARRAY) {
164+
((FromXmlParser) p).addVirtualWrapping(_namesToWrap, _caseInsensitive);
165+
}
158166
}
159167
}
160168

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

+14-15
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,19 @@ public final class XmlReadContext
4242
protected String _wrappedName;
4343

4444
/*
45-
/**********************************************************
46-
/* Simple instance reuse slots; speeds up things
47-
/* a bit (10-15%) for docs with lots of small
48-
/* arrays/objects (for which allocation was
45+
/**********************************************************************
46+
/* Simple instance reuse slots; speeds up things a bit (10-15%)
47+
/* for docs with lots of small arrays/objects (for which allocation was
4948
/* visible in profile stack frames)
50-
/**********************************************************
49+
/**********************************************************************
5150
*/
5251

5352
protected XmlReadContext _child = null;
5453

5554
/*
56-
/**********************************************************
55+
/**********************************************************************
5756
/* Instance construction, reuse
58-
/**********************************************************
57+
/**********************************************************************
5958
*/
6059

6160
public XmlReadContext(XmlReadContext parent, int type, int lineNr, int colNr)
@@ -90,9 +89,9 @@ public void setCurrentValue(Object v) {
9089
}
9190

9291
/*
93-
/**********************************************************
92+
/**********************************************************************
9493
/* Factory methods
95-
/**********************************************************
94+
/**********************************************************************
9695
*/
9796

9897
public static XmlReadContext createRootContext(int lineNr, int colNr) {
@@ -128,9 +127,9 @@ public final XmlReadContext createChildObjectContext(int lineNr, int colNr)
128127
}
129128

130129
/*
131-
/**********************************************************
130+
/**********************************************************************
132131
/* Abstract method implementation, overrides
133-
/**********************************************************
132+
/**********************************************************************
134133
*/
135134

136135
@Override
@@ -155,9 +154,9 @@ public final JsonLocation getStartLocation(Object srcRef) {
155154
}
156155

157156
/*
158-
/**********************************************************
157+
/**********************************************************************
159158
/* Extended API
160-
/**********************************************************
159+
/**********************************************************************
161160
*/
162161

163162
/**
@@ -188,9 +187,9 @@ protected void convertToArray() {
188187
}
189188

190189
/*
191-
/**********************************************************
190+
/**********************************************************************
192191
/* Overridden standard methods
193-
/**********************************************************
192+
/**********************************************************************
194193
*/
195194

196195
/**

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser469FailingTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void testIssue469WithDefaults() throws Exception
8383
"<outer>\n" +
8484
" <inner1/>\n" +
8585
" <inner2 str2='aaaa'/>\n" +
86+
// " <inner2><str2>aaaa</str2></inner2>\n" +
8687
"</outer>\n";
8788

8889
Outer469 result = mapper.readValue(xmlInput, Outer469.class);

0 commit comments

Comments
 (0)