@@ -116,10 +116,6 @@ private List<User> getUserList()
116
116
117
117
public void testIdWithJacksonRules () throws Exception
118
118
{
119
- String expected =
"[{\" id\" :11,\" username\" :\" 11\" ,\" email\" :\" [email protected] \" ,"
120
- +"\" department\" :{\" id\" :9,\" name\" :\" department9\" ,\" employees\" :["
121
- +
"11,{\" id\" :22,\" username\" :\" 22\" ,\" email\" :\" [email protected] \" ,"
122
- +
"\" department\" :9}]}},22,{\" id\" :33,\" username\" :\" 33\" ,\" email\" :\" [email protected] \" ,\" department\" :null}]" ;
123
119
ObjectMapper mapper = JsonMapper .builder ()
124
120
// true -> ignore XmlIDREF annotation
125
121
.annotationIntrospector (new JaxbAnnotationIntrospector (true ))
@@ -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