@@ -115,10 +115,6 @@ private List<User> getUserList()
115
115
116
116
public void testIdWithJacksonRules () throws Exception
117
117
{
118
- String expected =
"[{\" id\" :11,\" username\" :\" 11\" ,\" email\" :\" [email protected] \" ,"
119
- +"\" department\" :{\" id\" :9,\" name\" :\" department9\" ,\" employees\" :["
120
- +
"11,{\" id\" :22,\" username\" :\" 22\" ,\" email\" :\" [email protected] \" ,"
121
- +
"\" department\" :9}]}},22,{\" id\" :33,\" username\" :\" 33\" ,\" email\" :\" [email protected] \" ,\" department\" :null}]" ;
122
118
ObjectMapper mapper = JsonMapper .builder ()
123
119
// true -> ignore XmlIDREF annotation
124
120
.annotationIntrospector (new JaxbAnnotationIntrospector (TypeFactory .defaultInstance (),
@@ -128,13 +124,24 @@ public void testIdWithJacksonRules() throws Exception
128
124
// first, with default settings (first NOT as id)
129
125
List <User > users = getUserList ();
130
126
String json = mapper .writeValueAsString (users );
131
- assertEquals (expected , json );
132
127
133
128
List <User > result = mapper .readValue (json , new TypeReference <List <User >>() { });
134
129
assertEquals (3 , result .size ());
135
130
assertEquals (Long .valueOf (11 ), result .get (0 ).id );
131
+ assertEquals ("11" , result .get (0 ).username );
132
+ assertEquals (
"[email protected] " ,
result .
get (
0 ).
email );
133
+ assertEquals (Long .valueOf (9 ), result .get (0 ).department .id );
134
+ assertEquals ("department9" , result .get (0 ).department .name );
135
+ assertEquals (Long .valueOf (11 ), result .get (0 ).department .employees .get (0 ).id );
136
+ assertEquals (Long .valueOf (22 ), result .get (0 ).department .employees .get (1 ).id );
136
137
assertEquals (Long .valueOf (22 ), result .get (1 ).id );
138
+ assertEquals ("22" , result .get (1 ).username );
139
+ assertEquals (
"[email protected] " ,
result .
get (
1 ).
email );
140
+ assertEquals (result .get (0 ).department , result .get (1 ).department );
137
141
assertEquals (Long .valueOf (33 ), result .get (2 ).id );
142
+ assertEquals ("33" , result .get (2 ).username );
143
+ assertEquals (
"[email protected] " ,
result .
get (
2 ).
email );
144
+ assertEquals (null , result .get (2 ).department );
138
145
}
139
146
140
147
public void testIdWithJaxbRules () throws Exception
0 commit comments