9
9
import org .junit .Assert ;
10
10
11
11
import com .fasterxml .jackson .core .*;
12
-
13
12
import com .fasterxml .jackson .databind .*;
14
13
import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
14
+ import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
15
15
import com .fasterxml .jackson .databind .util .TokenBuffer ;
16
16
17
17
/**
@@ -43,7 +43,7 @@ public static class LeafMixIn
43
43
/**********************************************************
44
44
*/
45
45
46
- private final static ObjectMapper MAPPER = new ObjectMapper ();
46
+ private final ObjectMapper MAPPER = objectMapper ();
47
47
48
48
public void testAsInt () throws Exception
49
49
{
@@ -200,8 +200,7 @@ public void testEmbeddedObjectInObject() throws Exception
200
200
}
201
201
202
202
// [Issue#232]
203
- public void testBigDecimalAsPlainStringTreeConversion ()
204
- throws Exception
203
+ public void testBigDecimalAsPlainStringTreeConversion () throws Exception
205
204
{
206
205
ObjectMapper mapper = new ObjectMapper ();
207
206
mapper .enable (SerializationFeature .WRITE_BIGDECIMAL_AS_PLAIN );
@@ -213,5 +212,38 @@ public void testBigDecimalAsPlainStringTreeConversion()
213
212
assertEquals (1 , tree .size ());
214
213
assertTrue (tree .has ("pi" ));
215
214
}
215
+
216
+ static class CustomSerializedPojo implements JsonSerializable
217
+ {
218
+ private final ObjectNode node = JsonNodeFactory .instance .objectNode ();
219
+
220
+ public void setFoo (final String foo ) {
221
+ node .put ("foo" , foo );
222
+ }
223
+
224
+ @ Override
225
+ public void serialize (final JsonGenerator jgen , final SerializerProvider provider )
226
+ throws IOException
227
+ {
228
+ jgen .writeTree (node );
229
+ }
230
+
231
+ @ Override
232
+ public void serializeWithType (JsonGenerator jgen ,
233
+ SerializerProvider provider , TypeSerializer typeSer ) throws IOException {
234
+ typeSer .writeTypePrefixForObject (this , jgen );
235
+ serialize (jgen , provider );
236
+ typeSer .writeTypeSuffixForObject (this , jgen );
237
+ }
238
+ }
239
+
240
+ // [Issue#433]
241
+ public void testBeanToTree () throws Exception
242
+ {
243
+ final CustomSerializedPojo pojo = new CustomSerializedPojo ();
244
+ pojo .setFoo ("bar" );
245
+ final JsonNode node = MAPPER .valueToTree (pojo );
246
+ assertEquals (JsonNodeType .OBJECT , node .getNodeType ());
247
+ }
216
248
}
217
249
0 commit comments