2
2
3
3
import java .util .*;
4
4
5
+ import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
5
6
import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
6
7
import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
7
8
import com .fasterxml .jackson .dataformat .xml .annotation .*;
@@ -27,6 +28,32 @@ static class Optionals {
27
28
public List <Optional > optional ;
28
29
}
29
30
31
+ // For [Issue#101]
32
+ @ JacksonXmlRootElement (localName = "root" )
33
+ @ JsonPropertyOrder ({ "unwrapped" , "name" })
34
+ static class Root {
35
+ @ JacksonXmlProperty (localName = "unwrapped" )
36
+ @ JacksonXmlElementWrapper (useWrapping = false )
37
+ public List <UnwrappedElement > unwrapped ;
38
+
39
+ public String name ;
40
+ }
41
+
42
+ static class UnwrappedElement {
43
+ public UnwrappedElement () {}
44
+
45
+ public UnwrappedElement (String id , String type ) {
46
+ this .id = id ;
47
+ this .type = type ;
48
+ }
49
+
50
+ @ JacksonXmlProperty (isAttribute = true )
51
+ public String id ;
52
+
53
+ @ JacksonXmlProperty (isAttribute = true )
54
+ public String type ;
55
+ }
56
+
30
57
/*
31
58
/**********************************************************
32
59
/* Unit tests
@@ -51,4 +78,29 @@ public void testOptionalsWithMissingType() throws Exception
51
78
assertEquals ("123-456-7890" , opt .number );
52
79
assertEquals ("NOT SET" , opt .type );
53
80
}
54
- }
81
+
82
+ // [Issue#101]
83
+ public void testWithTwoAttributes () throws Exception
84
+ {
85
+ final String EXP = "<root>"
86
+ +"<unwrapped id=\" 1\" type=\" string\" />"
87
+ +"<unwrapped id=\" 2\" type=\" string\" />"
88
+ +"<name>test</name>"
89
+ +"</root>" ;
90
+ Root rootOb = new Root ();
91
+ rootOb .unwrapped = Arrays .asList (
92
+ new UnwrappedElement ("1" , "string" ),
93
+ new UnwrappedElement ("2" , "string" )
94
+ );
95
+ rootOb .name = "test" ;
96
+
97
+ // First, serialize, which works
98
+ String xml = MAPPER .writeValueAsString (rootOb );
99
+ assertEquals (EXP , xml );
100
+
101
+ // then try deserialize
102
+ Root result = MAPPER .readValue (xml , Root .class );
103
+ assertNotNull (result );
104
+ assertEquals (rootOb .name , result .name );
105
+ }
106
+ }
0 commit comments