Skip to content

Commit 41f8324

Browse files
committed
Revert "Fix int type transformed as BigDecimal value when parsing as Map (#529)" (#662)
This reverts commit da597e8.
1 parent 0988ae4 commit 41f8324

File tree

2 files changed

+11
-36
lines changed

2 files changed

+11
-36
lines changed

google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonFactoryTest.java

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,6 @@ public static class MapOfMapType {
482482

483483
static final String MAP_TYPE =
484484
"{\"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}}]}";
487485

488486
public void testParser_mapType() throws Exception {
489487
// parse
@@ -512,35 +510,16 @@ public void testParser_hashmapForMapType() throws Exception {
512510
parser = factory.createJsonParser(MAP_TYPE);
513511
parser.nextToken();
514512
@SuppressWarnings("unchecked")
515-
HashMap<String, ArrayList<ArrayMap<String, ArrayMap<String, Integer>>>> result =
516-
parser.parse(HashMap.class);
517-
// serialize
518-
assertEquals(MAP_TYPE, factory.toString(result));
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")
534513
HashMap<String, ArrayList<ArrayMap<String, ArrayMap<String, BigDecimal>>>> result =
535514
parser.parse(HashMap.class);
536515
// serialize
537-
assertEquals(BIGDECIMAL_MAP_TYPE, factory.toString(result));
516+
assertEquals(MAP_TYPE, factory.toString(result));
538517
// check parsed result
539518
ArrayList<ArrayMap<String, ArrayMap<String, BigDecimal>>> value = result.get("value");
540519
ArrayMap<String, ArrayMap<String, BigDecimal>> firstMap = value.get(0);
541520
ArrayMap<String, BigDecimal> map1 = firstMap.get("map1");
542-
BigDecimal bigDecimal = map1.get("k1");
543-
assertEquals(BigDecimal.valueOf(1.14566).setScale(5), bigDecimal);
521+
BigDecimal integer = map1.get("k1");
522+
assertEquals(1, integer.intValue());
544523
}
545524

546525
public static class WildCardTypes {
@@ -568,8 +547,8 @@ public void testParser_wildCardType() throws Exception {
568547
assertEquals(WILDCARD_TYPE, factory.toString(result));
569548
// check parsed result
570549
Collection<?>[] simple = result.simple;
571-
ArrayList<Integer> wildcard = (ArrayList<Integer>) simple[0];
572-
Integer wildcardFirstValue = wildcard.get(0);
550+
ArrayList<BigDecimal> wildcard = (ArrayList<BigDecimal>) simple[0];
551+
BigDecimal wildcardFirstValue = wildcard.get(0);
573552
assertEquals(1, wildcardFirstValue.intValue());
574553
Collection<? extends Integer>[] upper = result.upper;
575554
ArrayList<Integer> wildcardUpper = (ArrayList<Integer>) upper[0];
@@ -579,8 +558,8 @@ public void testParser_wildCardType() throws Exception {
579558
ArrayList<Integer> wildcardLower = (ArrayList<Integer>) lower[0];
580559
Integer wildcardFirstValueLower = wildcardLower.get(0);
581560
assertEquals(1, wildcardFirstValueLower.intValue());
582-
Map<String, Integer> map = (Map<String, Integer>) result.map;
583-
Integer mapValue = map.get("v");
561+
Map<String, BigDecimal> map = (Map<String, BigDecimal>) result.map;
562+
BigDecimal mapValue = map.get("v");
584563
assertEquals(1, mapValue.intValue());
585564
Map<String, Integer> mapUpper = (Map<String, Integer>) result.mapUpper;
586565
Integer mapUpperValue = mapUpper.get("v");
@@ -792,16 +771,16 @@ public void testParser_treemapForTypeVariableType() throws Exception {
792771
ArrayList<Object> arr = (ArrayList<Object>) result.get("arr");
793772
assertEquals(2, arr.size());
794773
assertEquals(Data.nullOf(Object.class), arr.get(0));
795-
ArrayList<Integer> subArr = (ArrayList<Integer>) arr.get(1);
774+
ArrayList<BigDecimal> subArr = (ArrayList<BigDecimal>) arr.get(1);
796775
assertEquals(2, subArr.size());
797776
assertEquals(Data.nullOf(Object.class), subArr.get(0));
798-
Integer arrValue = subArr.get(1);
777+
BigDecimal arrValue = subArr.get(1);
799778
assertEquals(1, arrValue.intValue());
800779
// null value
801780
Object nullValue = result.get("nullValue");
802781
assertEquals(Data.nullOf(Object.class), nullValue);
803782
// value
804-
Integer value = (Integer) result.get("value");
783+
BigDecimal value = (BigDecimal) result.get("value");
805784
assertEquals(1, value.intValue());
806785
}
807786

@@ -1540,7 +1519,7 @@ public void testParser_heterogeneousSchema_genericJson() throws Exception {
15401519
assertEquals(4, dog.numberOfLegs);
15411520
assertEquals(3, ((DogGenericJson) dog).tricksKnown);
15421521
assertEquals("this is not being used!", dog.get("unusedInfo"));
1543-
Integer foo = ((Integer) ((ArrayMap<String, Object>) dog.get("unused")).get("foo"));
1522+
BigDecimal foo = ((BigDecimal) ((ArrayMap<String, Object>) dog.get("unused")).get("foo"));
15441523
assertEquals(200, foo.intValue());
15451524
}
15461525

google-http-client/src/main/java/com/google/api/client/json/JsonParser.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,6 @@ private final Object parseValue(
828828
Preconditions.checkArgument(
829829
fieldContext == null || fieldContext.getAnnotation(JsonString.class) == null,
830830
"number type formatted as a JSON number cannot use @JsonString annotation");
831-
if (getCurrentToken() == JsonToken.VALUE_NUMBER_INT
832-
&& (valueClass == null || valueClass.isAssignableFrom(Integer.class))) {
833-
return getIntValue();
834-
}
835831
if (valueClass == null || valueClass.isAssignableFrom(BigDecimal.class)) {
836832
return getDecimalValue();
837833
}

0 commit comments

Comments
 (0)