Skip to content

Commit 38ceba0

Browse files
committed
Add a failing test for #525
1 parent 74233ec commit 38ceba0

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.annotation.JsonSubTypes;
7+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
8+
import com.fasterxml.jackson.annotation.JsonTypeName;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
11+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
12+
13+
// Tests for [dataformat-xml#525], related to relative order of "type"
14+
// property (as attribute) compared to other properties
15+
public class TypeInfoOrder525Test extends XmlTestBase
16+
{
17+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
18+
@JsonSubTypes({
19+
@JsonSubTypes.Type(value = ClassInfo525.class)
20+
})
21+
abstract static class TypeInfo525 {
22+
23+
}
24+
25+
@JsonTypeName("ClassInfo")
26+
static class ClassInfo525 extends TypeInfo525 {
27+
@JsonProperty List<ClassInfoElement525> element;
28+
@JsonProperty String name;
29+
}
30+
31+
static class ClassInfoElement525 {
32+
@JsonProperty BindingInfo525 binding;
33+
}
34+
35+
static class BindingInfo525 {
36+
@JsonProperty String description;
37+
}
38+
39+
/*
40+
/**********************************************************************
41+
/* Test methods
42+
/**********************************************************************
43+
*/
44+
45+
private final ObjectMapper MAPPER = mapperBuilder()
46+
.defaultUseWrapper(false)
47+
.build();
48+
49+
public void testTypeAfterOtherProperties() throws Exception {
50+
String xml =
51+
" <typeInfo name=\"MyName\" type=\"ClassInfo\">\n" +
52+
" <element>\n" +
53+
" <binding description=\"Test\"/>\n" +
54+
" </element>\n" +
55+
" </typeInfo>";
56+
57+
TypeInfo525 m = MAPPER.readValue(xml, TypeInfo525.class);
58+
assertEquals("MyName", ((ClassInfo525)m).name);
59+
assertEquals("Test", ((ClassInfo525)m).element.get(0).binding.description);
60+
}
61+
62+
public void testTypeBeforeOtherProperties() throws Exception {
63+
String xml =
64+
" <typeInfo type=\"ClassInfo\" name=\"MyName\">\n" +
65+
" <element>\n" +
66+
" <binding description=\"Test\"/>\n" +
67+
" </element>\n" +
68+
" </typeInfo>";
69+
70+
TypeInfo525 m = MAPPER.readValue(xml, TypeInfo525.class);
71+
assertEquals("MyName", ((ClassInfo525)m).name);
72+
assertEquals("Test", ((ClassInfo525)m).element.get(0).binding.description);
73+
}
74+
}

0 commit comments

Comments
 (0)