@@ -19,10 +19,19 @@ public class NumberSerTest extends BaseMapTest
1919
2020 static class IntWrapper {
2121 public int i ;
22-
2322 public IntWrapper (int value ) { i = value ; }
2423 }
25-
24+
25+ static class DoubleWrapper {
26+ public double value ;
27+ public DoubleWrapper (double v ) { value = v ; }
28+ }
29+
30+ static class BigDecimalWrapper {
31+ public BigDecimal value ;
32+ public BigDecimalWrapper (BigDecimal v ) { value = v ; }
33+ }
34+
2635 static class IntAsString {
2736 @ JsonFormat (shape =JsonFormat .Shape .STRING )
2837 @ JsonProperty ("value" )
@@ -39,6 +48,16 @@ static class DoubleAsString {
3948 public double value = -0.5 ;
4049 }
4150
51+ static class BigIntegerAsString {
52+ @ JsonFormat (shape =JsonFormat .Shape .STRING )
53+ public BigInteger value = BigInteger .valueOf (123456L );
54+ }
55+
56+ static class BigDecimalAsString {
57+ @ JsonFormat (shape =JsonFormat .Shape .STRING )
58+ public BigDecimal value = BigDecimal .valueOf (0.25 );
59+ }
60+
4261 static class NumberWrapper {
4362 // ensure it will use `Number` as statically force type, when looking for serializer
4463 @ JsonSerialize (as =Number .class )
@@ -87,15 +106,26 @@ public void testNumbersAsString() throws Exception
87106 assertEquals (aposToQuotes ("{'value':'3'}" ), MAPPER .writeValueAsString (new IntAsString ()));
88107 assertEquals (aposToQuotes ("{'value':'4'}" ), MAPPER .writeValueAsString (new LongAsString ()));
89108 assertEquals (aposToQuotes ("{'value':'-0.5'}" ), MAPPER .writeValueAsString (new DoubleAsString ()));
109+ assertEquals (aposToQuotes ("{'value':'0.25'}" ), MAPPER .writeValueAsString (new BigDecimalAsString ()));
110+ assertEquals (aposToQuotes ("{'value':'123456'}" ), MAPPER .writeValueAsString (new BigIntegerAsString ()));
90111 }
91112
92113 public void testConfigOverridesForNumbers () throws Exception
93114 {
94115 ObjectMapper mapper = new ObjectMapper ();
95116 mapper .configOverride (Integer .TYPE ) // for `int`
96117 .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .STRING ));
118+ mapper .configOverride (Double .TYPE ) // for `double`
119+ .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .STRING ));
120+ mapper .configOverride (BigDecimal .class )
121+ .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .STRING ));
122+
97123 assertEquals (aposToQuotes ("{'i':'3'}" ),
98124 mapper .writeValueAsString (new IntWrapper (3 )));
125+ assertEquals (aposToQuotes ("{'value':'0.75'}" ),
126+ mapper .writeValueAsString (new DoubleWrapper (0.75 )));
127+ assertEquals (aposToQuotes ("{'value':'-0.5'}" ),
128+ mapper .writeValueAsString (new BigDecimalWrapper (BigDecimal .valueOf (-0.5 ))));
99129 }
100130
101131 public void testNumberType () throws Exception
0 commit comments