Skip to content

Commit 6cb757c

Browse files
authored
create test cases for issue 615 (#801)
1 parent 3d297af commit 6cb757c

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package tools.jackson.dataformat.xml.deser;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import org.junit.jupiter.api.Test;
7+
import tools.jackson.dataformat.xml.XmlMapper;
8+
import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
9+
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;
10+
import tools.jackson.dataformat.xml.annotation.JacksonXmlText;
11+
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static tools.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT;
14+
import static tools.jackson.databind.cfg.DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS;
15+
16+
// [dataformat-xml#615]
17+
public class EntityClassList615Test {
18+
19+
static class EntityClass {
20+
@JacksonXmlText
21+
@JsonProperty("kto")
22+
public String kto;
23+
24+
@JacksonXmlProperty(isAttribute = true, localName = "Hkto")
25+
@JsonProperty("hkto")
26+
public String hkto;
27+
}
28+
29+
static class EntityClassList {
30+
31+
@JacksonXmlElementWrapper(localName = "entities")
32+
@JsonProperty("entity")
33+
public List<EntityClass> entityClassList;
34+
}
35+
36+
@Test
37+
void testXmlDeser() {
38+
XmlMapper xmlMapper = XmlMapper.builder()
39+
.defaultUseWrapper(false)
40+
.disable(WRITE_DATES_AS_TIMESTAMPS)
41+
.enable(ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
42+
.build();
43+
44+
String xmlString =
45+
"""
46+
<?xml version="1.0" encoding="UTF-8"?>
47+
<EntityclassList>
48+
<entities>
49+
<kto Hkto="6543210000">4561230000</kto>
50+
<kto Hkto="6543210000">5678910012</kto>
51+
<kto Hkto="">5678910013</kto>
52+
<kto Hkto="654321">567891</kto>
53+
<kto>5678910014</kto>
54+
<kto>567891</kto>
55+
</entities>
56+
</EntityclassList>""";
57+
58+
EntityClassList entityClassList = xmlMapper.readValue(xmlString, EntityClassList.class);
59+
assertNotNull(entityClassList);
60+
}
61+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package tools.jackson.dataformat.xml.tofix.records;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import org.junit.jupiter.api.Test;
7+
import tools.jackson.dataformat.xml.XmlMapper;
8+
import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
9+
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty;
10+
import tools.jackson.dataformat.xml.annotation.JacksonXmlText;
11+
import tools.jackson.dataformat.xml.testutil.failure.JacksonTestFailureExpected;
12+
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
import static tools.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT;
15+
import static tools.jackson.databind.cfg.DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS;
16+
17+
// [dataformat-xml#615]
18+
public class EntityRecordList615Test {
19+
20+
record EntityRecord(@JacksonXmlText
21+
@JsonProperty("kto")
22+
String kto,
23+
@JacksonXmlProperty(isAttribute = true, localName = "Hkto")
24+
@JsonProperty("hkto")
25+
String hkto) {
26+
}
27+
28+
record EntityRecordList(@JacksonXmlElementWrapper(localName = "entities")
29+
@JsonProperty("entity")
30+
List<EntityRecord> entityRecordList) {
31+
}
32+
33+
@Test
34+
@JacksonTestFailureExpected
35+
void testXmlDeser() {
36+
XmlMapper xmlMapper = XmlMapper.builder()
37+
.defaultUseWrapper(false)
38+
.disable(WRITE_DATES_AS_TIMESTAMPS)
39+
.enable(ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
40+
.build();
41+
42+
String xmlString =
43+
"""
44+
<?xml version="1.0" encoding="UTF-8"?>
45+
<EntityrecordList>
46+
<entities>
47+
<kto Hkto="6543210000">4561230000</kto>
48+
<kto Hkto="6543210000">5678910012</kto>
49+
<kto Hkto="">5678910013</kto>
50+
<kto Hkto="654321">567891</kto>
51+
<kto>5678910014</kto>
52+
<kto>567891</kto>
53+
</entities>
54+
</EntityrecordList>""";
55+
56+
EntityRecordList entityRecordList =
57+
xmlMapper.readValue(xmlString, EntityRecordList.class);
58+
assertNotNull(entityRecordList);
59+
}
60+
}

0 commit comments

Comments
 (0)