Skip to content

Commit 06b2537

Browse files
authored
Merge pull request #243 from khovanskiy/master
Failing unit test for issue #242
2 parents 63c121e + fb1c246 commit 06b2537

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonSubTypes;
4+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
5+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
6+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
7+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
8+
import org.junit.Test;
9+
10+
import java.util.List;
11+
12+
import static org.junit.Assert.assertEquals;
13+
14+
/**
15+
* Issue #242
16+
*/
17+
public class TestTypeAttributeOrder {
18+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = B.class)
19+
@JsonSubTypes({
20+
@JsonSubTypes.Type(value = B.class, name = "B")
21+
})
22+
static abstract class A {
23+
@JacksonXmlProperty(isAttribute = true)
24+
public Integer id;
25+
}
26+
27+
static class Attr {
28+
@JacksonXmlElementWrapper(useWrapping = false)
29+
public List<Param> param;
30+
}
31+
32+
static class Param {
33+
public String name;
34+
}
35+
36+
static class B extends A {
37+
public Attr attr;
38+
}
39+
40+
/*
41+
/**********************************************************
42+
/* Unit tests
43+
/**********************************************************
44+
*/
45+
private final XmlMapper MAPPER = new XmlMapper();
46+
47+
@Test
48+
public void testAttributeOrder() throws Exception {
49+
String content1 = "<A type=\"B\" id=\"1\"><attr><param name=\"1\"/><param name=\"2\"/></attr></A>";
50+
B b1 = (B) MAPPER.readValue(content1, A.class);
51+
assertEquals(2, b1.attr.param.size());
52+
String content2 = "<A id=\"1\" type=\"B\"><attr><param name=\"1\"/><param name=\"2\"/></attr></A>";
53+
B b2 = (B) MAPPER.readValue(content2, A.class);
54+
assertEquals(2, b2.attr.param.size());
55+
}
56+
}

0 commit comments

Comments
 (0)