@@ -482,6 +482,8 @@ public static class MapOfMapType {
482
482
483
483
static final String MAP_TYPE =
484
484
"{\" value\" :[{\" map1\" :{\" k1\" :1,\" k2\" :2},\" map2\" :{\" kk1\" :3,\" kk2\" :4}}]}" ;
485
+ static final String BIGDECIMAL_MAP_TYPE =
486
+ "{\" value\" :[{\" map1\" :{\" k1\" :1.14566,\" k2\" :2.14},\" map2\" :{\" kk1\" :3.29,\" kk2\" :4.69}}]}" ;
485
487
486
488
public void testParser_mapType () throws Exception {
487
489
// parse
@@ -510,16 +512,35 @@ public void testParser_hashmapForMapType() throws Exception {
510
512
parser = factory .createJsonParser (MAP_TYPE );
511
513
parser .nextToken ();
512
514
@ SuppressWarnings ("unchecked" )
513
- HashMap <String , ArrayList <ArrayMap <String , ArrayMap <String , BigDecimal >>>> result =
515
+ HashMap <String , ArrayList <ArrayMap <String , ArrayMap <String , Integer >>>> result =
514
516
parser .parse (HashMap .class );
515
517
// serialize
516
518
assertEquals (MAP_TYPE , factory .toString (result ));
517
519
// check parsed result
520
+ ArrayList <ArrayMap <String , ArrayMap <String , Integer >>> value = result .get ("value" );
521
+ ArrayMap <String , ArrayMap <String , Integer >> firstMap = value .get (0 );
522
+ ArrayMap <String , Integer > map1 = firstMap .get ("map1" );
523
+ Integer integer = map1 .get ("k1" );
524
+ assertEquals (1 , integer .intValue ());
525
+ }
526
+
527
+ public void testParser_hashmapForMapTypeWithBigDecimal () throws Exception {
528
+ // parse
529
+ JsonFactory factory = newFactory ();
530
+ JsonParser parser ;
531
+ parser = factory .createJsonParser (BIGDECIMAL_MAP_TYPE );
532
+ parser .nextToken ();
533
+ @ SuppressWarnings ("unchecked" )
534
+ HashMap <String , ArrayList <ArrayMap <String , ArrayMap <String , BigDecimal >>>> result =
535
+ parser .parse (HashMap .class );
536
+ // serialize
537
+ assertEquals (BIGDECIMAL_MAP_TYPE , factory .toString (result ));
538
+ // check parsed result
518
539
ArrayList <ArrayMap <String , ArrayMap <String , BigDecimal >>> value = result .get ("value" );
519
540
ArrayMap <String , ArrayMap <String , BigDecimal >> firstMap = value .get (0 );
520
541
ArrayMap <String , BigDecimal > map1 = firstMap .get ("map1" );
521
- BigDecimal integer = map1 .get ("k1" );
522
- assertEquals (1 , integer . intValue () );
542
+ BigDecimal bigDecimal = map1 .get ("k1" );
543
+ assertEquals (BigDecimal . valueOf ( 1.14566 ). setScale ( 5 ), bigDecimal );
523
544
}
524
545
525
546
public static class WildCardTypes {
@@ -547,8 +568,8 @@ public void testParser_wildCardType() throws Exception {
547
568
assertEquals (WILDCARD_TYPE , factory .toString (result ));
548
569
// check parsed result
549
570
Collection <?>[] simple = result .simple ;
550
- ArrayList <BigDecimal > wildcard = (ArrayList <BigDecimal >) simple [0 ];
551
- BigDecimal wildcardFirstValue = wildcard .get (0 );
571
+ ArrayList <Integer > wildcard = (ArrayList <Integer >) simple [0 ];
572
+ Integer wildcardFirstValue = wildcard .get (0 );
552
573
assertEquals (1 , wildcardFirstValue .intValue ());
553
574
Collection <? extends Integer >[] upper = result .upper ;
554
575
ArrayList <Integer > wildcardUpper = (ArrayList <Integer >) upper [0 ];
@@ -558,8 +579,8 @@ public void testParser_wildCardType() throws Exception {
558
579
ArrayList <Integer > wildcardLower = (ArrayList <Integer >) lower [0 ];
559
580
Integer wildcardFirstValueLower = wildcardLower .get (0 );
560
581
assertEquals (1 , wildcardFirstValueLower .intValue ());
561
- Map <String , BigDecimal > map = (Map <String , BigDecimal >) result .map ;
562
- BigDecimal mapValue = map .get ("v" );
582
+ Map <String , Integer > map = (Map <String , Integer >) result .map ;
583
+ Integer mapValue = map .get ("v" );
563
584
assertEquals (1 , mapValue .intValue ());
564
585
Map <String , Integer > mapUpper = (Map <String , Integer >) result .mapUpper ;
565
586
Integer mapUpperValue = mapUpper .get ("v" );
@@ -771,16 +792,16 @@ public void testParser_treemapForTypeVariableType() throws Exception {
771
792
ArrayList <Object > arr = (ArrayList <Object >) result .get ("arr" );
772
793
assertEquals (2 , arr .size ());
773
794
assertEquals (Data .nullOf (Object .class ), arr .get (0 ));
774
- ArrayList <BigDecimal > subArr = (ArrayList <BigDecimal >) arr .get (1 );
795
+ ArrayList <Integer > subArr = (ArrayList <Integer >) arr .get (1 );
775
796
assertEquals (2 , subArr .size ());
776
797
assertEquals (Data .nullOf (Object .class ), subArr .get (0 ));
777
- BigDecimal arrValue = subArr .get (1 );
798
+ Integer arrValue = subArr .get (1 );
778
799
assertEquals (1 , arrValue .intValue ());
779
800
// null value
780
801
Object nullValue = result .get ("nullValue" );
781
802
assertEquals (Data .nullOf (Object .class ), nullValue );
782
803
// value
783
- BigDecimal value = (BigDecimal ) result .get ("value" );
804
+ Integer value = (Integer ) result .get ("value" );
784
805
assertEquals (1 , value .intValue ());
785
806
}
786
807
@@ -1519,7 +1540,7 @@ public void testParser_heterogeneousSchema_genericJson() throws Exception {
1519
1540
assertEquals (4 , dog .numberOfLegs );
1520
1541
assertEquals (3 , ((DogGenericJson ) dog ).tricksKnown );
1521
1542
assertEquals ("this is not being used!" , dog .get ("unusedInfo" ));
1522
- BigDecimal foo = ((BigDecimal ) ((ArrayMap <String , Object >) dog .get ("unused" )).get ("foo" ));
1543
+ Integer foo = ((Integer ) ((ArrayMap <String , Object >) dog .get ("unused" )).get ("foo" ));
1523
1544
assertEquals (200 , foo .intValue ());
1524
1545
}
1525
1546
0 commit comments