Skip to content

Commit 6df610c

Browse files
committed
Merge branch '2.11' into 2.12
2 parents c1db62b + fab0b8b commit 6df610c

File tree

5 files changed

+89
-145
lines changed

5 files changed

+89
-145
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import java.util.List;
44

5-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6-
75
import com.fasterxml.jackson.databind.*;
86
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
97
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
108
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
9+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
1110

1211
public class CaseInsensitiveDeser273Test extends XmlTestBase
1312
{
@@ -26,7 +25,7 @@ public void setElement(List<Depot273> l) {
2625
}
2726
}
2827

29-
@JsonIgnoreProperties(ignoreUnknown = true)
28+
// @JsonIgnoreProperties(ignoreUnknown = true)
3029
static class Depot273
3130
{
3231
@JacksonXmlProperty(isAttribute = true)
@@ -35,6 +34,10 @@ static class Depot273
3534
@JacksonXmlProperty(isAttribute = true)
3635
public String name;
3736

37+
// Should not actually be necessary but...
38+
@JacksonXmlText
39+
public String text;
40+
3841
public void setNumber(String n) {
3942
//System.err.println("SetNumber: '"+n+"'");
4043
number = n;

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/ListDeser191Test.java

-40
This file was deleted.

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/ListDeser294Test.java

-58
This file was deleted.

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/ListDeser393Test.java

+13-44
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,44 @@
88

99
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
1010
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
11-
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
1211
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
1312

1413
public class ListDeser393Test extends XmlTestBase
1514
{
1615
@JacksonXmlRootElement(localName = "result")
1716
@JsonInclude(JsonInclude.Include.NON_NULL)
1817
static class Value393 {
19-
private Prices prices = new Prices();
18+
private Prices393 prices = new Prices393();
2019

21-
public void setPrices(Prices prices) {
20+
public void setPrices(Prices393 prices) {
2221
this.prices = prices;
2322
}
2423

25-
@JacksonXmlProperty(localName = "prices")
26-
public Prices getPrices() {
24+
public Prices393 getPrices() {
2725
return this.prices;
2826
}
2927
}
3028

3129
@JacksonXmlRootElement(localName = "prices")
32-
static class Prices {
33-
private List<Price> price = new ArrayList<Price>();
30+
static class Prices393 {
31+
private List<Price393> price = new ArrayList<Price393>();
3432

35-
public void setPrice(List<Price> price) {
33+
public void setPrice(List<Price393> price) {
3634
this.price = price;
3735
}
3836

3937
@JacksonXmlElementWrapper(useWrapping = false)
40-
public List<Price> getPrice() {
38+
public List<Price393> getPrice() {
4139
return this.price;
4240
}
4341
}
4442

45-
static class Price {
43+
static class Price393 {
4644
private String price;
4745
private String num;
4846

49-
protected Price() { }
50-
public Price(String p, String n) {
47+
protected Price393() { }
48+
public Price393(String p, String n) {
5149
price = p;
5250
num = n;
5351
}
@@ -80,37 +78,6 @@ public String getNum() {
8078
// [dataform#393]
8179
public void testDeser393() throws Exception
8280
{
83-
// for debugging:
84-
/*
85-
Value393 input = new Value393();
86-
Prices prices = new Prices();
87-
prices.setPrice(Arrays.asList(
88-
new Price("100", "7.0"),
89-
new Price("100", "4.0")
90-
));
91-
input.setPrices(prices);
92-
93-
String xml = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input);
94-
System.out.println("XML:\n"+xml);
95-
*/
96-
/*
97-
String content = //"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "\n" +
98-
"<result>\n"
99-
+ " <prices>\n"
100-
+ " <price>\n"
101-
+ " <num>100</num>\n"
102-
+ " <price>7.0</price>\n"
103-
+ " </price>\n"
104-
+ " <price>\n"
105-
+ " <num>100</num>\n"
106-
+ " <price>4.0</price>\n"
107-
+ " </price>"
108-
+ " </prices>\n"
109-
+ "</result>";
110-
Value393 result = MAPPER.readValue(content, Value393.class);
111-
assertNotNull(result);
112-
*/
113-
11481
String content =
11582
"<prices>\n"
11683
+ " <price>\n"
@@ -122,7 +89,9 @@ public void testDeser393() throws Exception
12289
+ " <price>4.0</price>\n"
12390
+ " </price>"
12491
+ "</prices>\n";
125-
Prices result = MAPPER.readValue(content, Prices.class);
92+
Prices393 result = MAPPER.readValue(content, Prices393.class);
12693
assertNotNull(result);
94+
assertNotNull(result.getPrice());
95+
assertEquals(2, result.getPrice().size());
12796
}
12897
}

src/test/java/com/fasterxml/jackson/dataformat/xml/lists/ListDeserializationTest.java

+70
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.*;
44

5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
57
import com.fasterxml.jackson.databind.SerializationFeature;
68
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
79
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
@@ -69,6 +71,32 @@ static class ListBeanUnwrapped
6971
public List<Integer> values;
7072
}
7173

74+
// [dataformat-xml#191]
75+
static class TestList191 {
76+
@JacksonXmlElementWrapper(useWrapping = true, localName = "items")
77+
@JacksonXmlProperty(localName = "item")
78+
public ArrayList<ListItem191> items;
79+
}
80+
81+
static class ListItem191 {
82+
@JacksonXmlProperty(isAttribute = true)
83+
public String name;
84+
}
85+
86+
// [dataformat-xml#294]
87+
@JacksonXmlRootElement(localName = "levels")
88+
static class RootLevel294 {
89+
@JacksonXmlElementWrapper(useWrapping = false)
90+
@JacksonXmlProperty(localName = "sublevel")
91+
public List<Sublevel294> sublevels = new ArrayList<>();
92+
}
93+
94+
@JsonPropertyOrder({ "id", "sublevel" })
95+
static class Sublevel294 {
96+
public Integer id;
97+
public String sublevel;
98+
}
99+
72100
/*
73101
/**********************************************************
74102
/* Unit tests
@@ -164,4 +192,46 @@ public void testUnwrappedListBeanDeser() throws Exception
164192
assertEquals(Integer.valueOf(2), bean.values.get(1));
165193
assertEquals(Integer.valueOf(3), bean.values.get(2));
166194
}
195+
196+
// [dataformat-xml#191]
197+
public void testListDeser191() throws Exception
198+
{
199+
final String XML =
200+
"<TestList>\n"+
201+
" <items>\n"+
202+
" <item name='Item1'/>\n"+
203+
" <item name='Item2'> </item>\n"+ // important: at least one ws char between start/end
204+
" <item name='Item3'/>\n"+
205+
" </items>\n"+
206+
"</TestList>"
207+
;
208+
TestList191 testList = MAPPER.readValue(XML, TestList191.class);
209+
assertNotNull(testList);
210+
assertNotNull(testList.items);
211+
assertEquals(3, testList.items.size());
212+
}
213+
214+
// [dataformat-xml#294]
215+
public void testNestedLists294() throws Exception
216+
{
217+
RootLevel294 tree = new RootLevel294();
218+
tree.sublevels.add(_newSublevel(1, "Name A"));
219+
tree.sublevels.add(_newSublevel(2, "Name B"));
220+
String xml = MAPPER
221+
.writerWithDefaultPrettyPrinter()
222+
.writeValueAsString(tree);
223+
//System.err.println("XML:\n"+xml);
224+
RootLevel294 resTree = MAPPER.readValue(xml, RootLevel294.class);
225+
assertNotNull(resTree);
226+
assertNotNull(resTree.sublevels);
227+
assertEquals(2, resTree.sublevels.size());
228+
assertEquals("Name B", resTree.sublevels.get(1).sublevel);
229+
}
230+
231+
private Sublevel294 _newSublevel(Integer id, String sublevel) {
232+
Sublevel294 res = new Sublevel294();
233+
res.id = id;
234+
res.sublevel = sublevel;
235+
return res;
236+
}
167237
}

0 commit comments

Comments
 (0)