1
1
package com .fasterxml .jackson .module .blackbird .ser ;
2
2
3
+ import com .fasterxml .jackson .annotation .JsonFormat ;
4
+
3
5
import com .fasterxml .jackson .databind .ObjectMapper ;
4
6
import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
5
7
import com .fasterxml .jackson .databind .ser .std .ToStringSerializer ;
6
8
7
9
import com .fasterxml .jackson .module .blackbird .BlackbirdTestBase ;
8
10
9
- // [modules-base#117]
10
11
public class JDKScalarsSerTest extends BlackbirdTestBase
11
12
{
13
+ // [modules-base#117]
12
14
static class Bean117UsingJsonSerialize {
13
15
@ JsonSerialize (using = ToStringSerializer .class )
14
16
public int getValue () {
15
17
return 42 ;
16
18
}
17
19
}
18
20
21
+ // [modules-base#118]
22
+ static class Bean118IntUsingJsonFormat {
23
+ @ JsonFormat (shape = JsonFormat .Shape .STRING )
24
+ public int getValue () {
25
+ return 42 ;
26
+ }
27
+ }
28
+
29
+ static class Bean118LongUsingJsonFormat {
30
+ @ JsonFormat (shape = JsonFormat .Shape .STRING )
31
+ public long getValue () {
32
+ return -137L ;
33
+ }
34
+ }
35
+
19
36
private final ObjectMapper MAPPER = newObjectMapper ();
20
37
private final ObjectMapper VANILLA_MAPPER = newVanillaJSONMapper ();
21
38
@@ -27,4 +44,22 @@ public void testIntAsStringWithJsonSerialize() throws Exception
27
44
assertEquals (EXP_JSON , VANILLA_MAPPER .writeValueAsString (input ));
28
45
assertEquals (EXP_JSON , MAPPER .writeValueAsString (input ));
29
46
}
47
+
48
+ // [modules-base#118]
49
+ public void testIntAsStringWithJsonFormat () throws Exception
50
+ {
51
+ final String EXP_JSON = "{\" value\" :\" 42\" }" ;
52
+ final Object input = new Bean118IntUsingJsonFormat ();
53
+ assertEquals (EXP_JSON , VANILLA_MAPPER .writeValueAsString (input ));
54
+ assertEquals (EXP_JSON , MAPPER .writeValueAsString (input ));
55
+ }
56
+
57
+ // [modules-base#118]
58
+ public void testLongAsStringWithJsonFormat () throws Exception
59
+ {
60
+ final String EXP_JSON = "{\" value\" :\" -137\" }" ;
61
+ final Object input = new Bean118LongUsingJsonFormat ();
62
+ assertEquals (EXP_JSON , VANILLA_MAPPER .writeValueAsString (input ));
63
+ assertEquals (EXP_JSON , MAPPER .writeValueAsString (input ));
64
+ }
30
65
}
0 commit comments