Skip to content

Commit bc0adc2

Browse files
authored
Create reproducer test case for #509 (#604)
1 parent 36459c6 commit bc0adc2

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import java.util.*;
4+
5+
import org.junit.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
8+
9+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
10+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
11+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
12+
13+
import static org.junit.Assert.assertEquals;
14+
15+
// For [dataformat-xml#509]
16+
public class UnexpectedNonWhitespaceText509Test {
17+
@JsonPropertyOrder({ "key", "content" })
18+
static class Data {
19+
@JacksonXmlText
20+
public String content;
21+
@JacksonXmlProperty(isAttribute=true)
22+
protected java.lang.String key;
23+
24+
public java.lang.String getKey() {
25+
return key;
26+
}
27+
28+
public void setKey(java.lang.String value) {
29+
this.key = value;
30+
}
31+
}
32+
33+
static class MetaData {
34+
protected List<Data> data;
35+
36+
public List<Data> getData() {
37+
if (data == null) {
38+
data = new ArrayList<>();
39+
}
40+
return this.data;
41+
}
42+
43+
public void setData(List<Data> data) {
44+
this.data = data;
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return Objects.toString(data);
50+
}
51+
}
52+
53+
private final XmlMapper XML_MAPPER = new XmlMapper();
54+
55+
@Test
56+
public void testDeSerData() throws Exception {
57+
Data value = deSer("<data key=\"MadeWith\">Text Editor</data>", Data.class);
58+
assertEquals("\"key\" attribute not correctly deserialized", value.getKey(), "MadeWith");
59+
}
60+
61+
@Test
62+
public void testDeSerMetaData() throws Exception {
63+
MetaData value = deSer("<metaData>\n" //
64+
+ " <data key=\"MadeWith\">Text Editor</data>\n" //
65+
+ " <data key=\"Version\">1.0.0</data>\n" //
66+
+ "</metaData>", MetaData.class);
67+
List<Data> entries = value.getData();
68+
assertEquals("\"data\" not correctly deserialized", entries.size(), 2);
69+
Data entry = entries.get(0);
70+
assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "MadeWith");
71+
entry = entries.get(1);
72+
assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "Version");
73+
}
74+
75+
private <T> T deSer(String xmlString, Class<T> clazz) throws Exception {
76+
return XML_MAPPER.readerFor(clazz).readValue(xmlString);
77+
}
78+
}

0 commit comments

Comments
 (0)