File tree 1 file changed +18
-0
lines changed
gson/src/main/java/com/google/gson
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,12 @@ public boolean equals(Object obj) {
267
267
if (value == null ) {
268
268
return other .value == null ;
269
269
}
270
+ if (isBigNumber (this ) || isBigNumber (other )) {
271
+ // As a BigDecimal is essentially a wrapper around a BigInteger that
272
+ // "remembers where the decimal point is", casting BigInteger to BigDecimal
273
+ // makes more sense, avoiding max long/double values comparison.
274
+ return getAsBigDecimal ().equals (other .getAsBigDecimal ());
275
+ }
270
276
if (isIntegral (this ) && isIntegral (other )) {
271
277
return getAsNumber ().longValue () == other .getAsNumber ().longValue ();
272
278
}
@@ -292,4 +298,16 @@ private static boolean isIntegral(JsonPrimitive primitive) {
292
298
}
293
299
return false ;
294
300
}
301
+
302
+ private static boolean isBigInteger (JsonPrimitive primitive ) {
303
+ return primitive .value instanceof BigDecimal ;
304
+ }
305
+
306
+ private static boolean isBigDecimal (JsonPrimitive primitive ) {
307
+ return primitive .value instanceof BigDecimal ;
308
+ }
309
+
310
+ private static boolean isBigNumber (JsonPrimitive primitive ) {
311
+ return isBigDecimal (primitive ) || isBigInteger (primitive );
312
+ }
295
313
}
You can’t perform that action at this time.
0 commit comments