@@ -25,9 +25,7 @@ public void testObjectNodeSerialization() throws Exception
25
25
ObjectNode misc = root .with ("misc" );
26
26
misc .put ("value" , 0.25 );
27
27
28
- byte [] ser = jdkSerialize (root );
29
- JsonNode result = jdkDeserialize (ser );
30
- assertEquals (root , result );
28
+ testNodeRoundtrip (root );
31
29
}
32
30
33
31
// [databind#18]: Allow JDK serialization of `ArrayNode`
@@ -39,17 +37,36 @@ public void testArrayNodeSerialization() throws Exception
39
37
props .put ("answer" , 42 );
40
38
root .add (137 );
41
39
42
- byte [] ser = jdkSerialize (root );
43
- JsonNode result = jdkDeserialize (ser );
44
- assertEquals (root , result );
40
+ testNodeRoundtrip (root );
41
+ }
42
+
43
+ // and then also some scalar types
44
+ public void testScalarSerialization () throws Exception
45
+ {
46
+ testNodeRoundtrip (MAPPER .getNodeFactory ().nullNode ());
47
+
48
+ testNodeRoundtrip (MAPPER .getNodeFactory ().textNode ("Foobar" ));
49
+
50
+ testNodeRoundtrip (MAPPER .getNodeFactory ().booleanNode (true ));
51
+ testNodeRoundtrip (MAPPER .getNodeFactory ().booleanNode (false ));
52
+
53
+ testNodeRoundtrip (MAPPER .getNodeFactory ().numberNode (123 ));
54
+ testNodeRoundtrip (MAPPER .getNodeFactory ().numberNode (-12345678901234L ));
45
55
}
46
56
47
57
/*
48
58
/**********************************************************
49
59
/* Helper methods
50
60
/**********************************************************
51
61
*/
52
-
62
+
63
+ protected void testNodeRoundtrip (JsonNode input ) throws Exception
64
+ {
65
+ byte [] ser = jdkSerialize (input );
66
+ JsonNode result = jdkDeserialize (ser );
67
+ assertEquals (input , result );
68
+ }
69
+
53
70
protected byte [] jdkSerialize (Object o ) throws IOException
54
71
{
55
72
ByteArrayOutputStream bytes = new ByteArrayOutputStream (1000 );
0 commit comments