1
1
package com .fasterxml .jackson .databind .ser ;
2
2
3
3
import com .fasterxml .jackson .annotation .*;
4
-
4
+ import com . fasterxml . jackson . databind . JsonNode ;
5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
6
7
7
/**
8
8
* This unit test suite tests functioning of {@link JsonRawValue}
9
9
* annotation with bean serialization.
10
10
*/
11
- public class TestJsonRawValue
11
+ public class RawValueTest
12
12
extends com .fasterxml .jackson .databind .BaseMapTest
13
13
{
14
14
/*
@@ -31,37 +31,53 @@ final static class ClassGetter<T>
31
31
32
32
@ JsonProperty @ JsonRawValue protected T value () { return _value ; }
33
33
}
34
-
34
+
35
+ // [databind#348]
36
+ static class RawWrapped
37
+ {
38
+ @ JsonRawValue
39
+ private final String json ;
40
+
41
+ public RawWrapped (String str ) {
42
+ json = str ;
43
+ }
44
+ }
45
+
35
46
/*
36
47
/*********************************************************
37
48
/* Test cases
38
49
/*********************************************************
39
50
*/
40
51
52
+ private final ObjectMapper MAPPER = objectMapper ();
53
+
41
54
public void testSimpleStringGetter () throws Exception
42
55
{
43
- ObjectMapper m = new ObjectMapper ();
44
56
String value = "abc" ;
45
- String result = m .writeValueAsString (new ClassGetter <String >(value ));
57
+ String result = MAPPER .writeValueAsString (new ClassGetter <String >(value ));
46
58
String expected = String .format ("{\" nonRaw\" :\" %s\" ,\" raw\" :%s,\" value\" :%s}" , value , value , value );
47
59
assertEquals (expected , result );
48
60
}
49
61
50
62
public void testSimpleNonStringGetter () throws Exception
51
63
{
52
- ObjectMapper m = new ObjectMapper ();
53
64
int value = 123 ;
54
- String result = m .writeValueAsString (new ClassGetter <Integer >(value ));
65
+ String result = MAPPER .writeValueAsString (new ClassGetter <Integer >(value ));
55
66
String expected = String .format ("{\" nonRaw\" :%d,\" raw\" :%d,\" value\" :%d}" , value , value , value );
56
67
assertEquals (expected , result );
57
68
}
58
69
59
70
public void testNullStringGetter () throws Exception
60
71
{
61
- ObjectMapper m = new ObjectMapper ();
62
- String result = m .writeValueAsString (new ClassGetter <String >(null ));
72
+ String result = MAPPER .writeValueAsString (new ClassGetter <String >(null ));
63
73
String expected = "{\" nonRaw\" :null,\" raw\" :null,\" value\" :null}" ;
64
74
assertEquals (expected , result );
65
75
}
66
76
77
+ public void testWithValueToTree () throws Exception
78
+ {
79
+ JsonNode w = MAPPER .valueToTree (new RawWrapped ("{ }" ));
80
+ assertNotNull (w );
81
+ assertEquals ("{\" json\" :{ }}" , MAPPER .writeValueAsString (w ));
82
+ }
67
83
}
0 commit comments