1
1
package com .fasterxml .jackson .databind .misc ;
2
2
3
- import com . fasterxml . jackson . databind .* ;
3
+ import java . util . Arrays ;
4
4
5
+ import com .fasterxml .jackson .databind .*;
5
6
import com .fasterxml .jackson .databind .util .JSONPObject ;
7
+ import com .fasterxml .jackson .databind .util .JSONWrappedObject ;
6
8
7
9
public class TestJSONP
8
10
extends BaseMapTest
@@ -18,23 +20,23 @@ public Impl(String a, String b) {
18
20
this .b = b ;
19
21
}
20
22
}
21
-
23
+
24
+ private final ObjectMapper MAPPER = new ObjectMapper ();
25
+
22
26
public void testSimpleScalars () throws Exception
23
27
{
24
- ObjectMapper m = new ObjectMapper ();
25
28
assertEquals ("callback(\" abc\" )" ,
26
- serializeAsString ( m , new JSONPObject ("callback" , "abc" )));
29
+ MAPPER . writeValueAsString ( new JSONPObject ("callback" , "abc" )));
27
30
assertEquals ("calc(123)" ,
28
- serializeAsString ( m , new JSONPObject ("calc" , Integer .valueOf (123 ))));
31
+ MAPPER . writeValueAsString ( new JSONPObject ("calc" , Integer .valueOf (123 ))));
29
32
assertEquals ("dummy(null)" ,
30
- serializeAsString ( m , new JSONPObject ("dummy" , null )));
33
+ MAPPER . writeValueAsString ( new JSONPObject ("dummy" , null )));
31
34
}
32
35
33
36
public void testSimpleBean () throws Exception
34
37
{
35
- ObjectMapper m = new ObjectMapper ();
36
38
assertEquals ("xxx({\" a\" :\" 123\" ,\" b\" :\" 456\" })" ,
37
- serializeAsString ( m , new JSONPObject ("xxx" ,
39
+ MAPPER . writeValueAsString ( new JSONPObject ("xxx" ,
38
40
new Impl ("123" , "456" ))));
39
41
}
40
42
@@ -44,10 +46,16 @@ public void testSimpleBean() throws Exception
44
46
*/
45
47
public void testWithType () throws Exception
46
48
{
47
- ObjectMapper m = new ObjectMapper ();
48
49
Object ob = new Impl ("abc" , "def" );
49
- JavaType type = m .constructType (Base .class );
50
+ JavaType type = MAPPER .constructType (Base .class );
50
51
assertEquals ("do({\" a\" :\" abc\" })" ,
51
- serializeAsString (m , new JSONPObject ("do" , ob , type )));
52
+ MAPPER .writeValueAsString (new JSONPObject ("do" , ob , type )));
53
+ }
54
+
55
+ public void testGeneralWrapping () throws Exception
56
+ {
57
+ JSONWrappedObject input = new JSONWrappedObject ("/*Foo*/" , "\n // the end" ,
58
+ Arrays .asList ());
59
+ assertEquals ("/*Foo*/[]\n // the end" , MAPPER .writeValueAsString (input ));
52
60
}
53
61
}
0 commit comments