File tree Expand file tree Collapse file tree
main/java/com/jsoniter/output
test/java/com/jsoniter/output Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import java .io .IOException ;
99import java .lang .reflect .ParameterizedType ;
1010import java .lang .reflect .Type ;
11+ import java .math .BigDecimal ;
12+ import java .math .BigInteger ;
1113import java .util .HashMap ;
1214import java .util .IdentityHashMap ;
1315import java .util .Map ;
@@ -236,6 +238,31 @@ public Any wrap(Object obj) {
236238 return JsonStream .wrap (obj );
237239 }
238240 });
241+
242+ put (BigDecimal .class , new Encoder () {
243+ @ Override
244+ public void encode (Object obj , JsonStream stream ) throws IOException {
245+ BigDecimal val = (BigDecimal ) obj ;
246+ stream .writeVal (val .toString ());
247+ }
248+
249+ @ Override
250+ public Any wrap (Object obj ) {
251+ return Any .wrap (obj .toString ());
252+ }
253+ });
254+ put (BigInteger .class , new Encoder () {
255+ @ Override
256+ public void encode (Object obj , JsonStream stream ) throws IOException {
257+ BigInteger val = (BigInteger ) obj ;
258+ stream .writeVal (val .toString ());
259+ }
260+
261+ @ Override
262+ public Any wrap (Object obj ) {
263+ return Any .wrap (obj .toString ());
264+ }
265+ });
239266 }};
240267
241268 public static String genWriteOp (String code , Type valueType ) {
Original file line number Diff line number Diff line change 44
55import java .io .ByteArrayOutputStream ;
66import java .io .IOException ;
7+ import java .math .BigDecimal ;
8+ import java .math .BigInteger ;
79
810public class TestNative extends TestCase {
911
@@ -110,4 +112,16 @@ public void test_boolean() throws IOException {
110112 stream .close ();
111113 assertEquals ("truefalse" .replace ('\'' , '"' ), baos .toString ());
112114 }
115+
116+ public void test_big_decimal () throws IOException {
117+ stream .writeVal (new BigDecimal ("12.34" ));
118+ stream .close ();
119+ assertEquals ("'12.34'" .replace ('\'' , '"' ), baos .toString ());
120+ }
121+
122+ public void test_big_integer () throws IOException {
123+ stream .writeVal (new BigInteger ("1234" ));
124+ stream .close ();
125+ assertEquals ("'1234'" .replace ('\'' , '"' ), baos .toString ());
126+ }
113127}
You can’t perform that action at this time.
0 commit comments