Skip to content

Commit 731b6f3

Browse files
committed
check if a value is a Number before casting
- In some rare cases when generating the JSON diff for a given key, it is possible that the new value is not a number while the old value is an Integer. - While I can't think of a particular key that can have either an int or string value, crashes have been reported. - Let's check the old value to be of type Number, maybe it could be a float/double before serialization.
1 parent 9836682 commit 731b6f3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/JSONUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ else if (includeFields != null && includeFields.contains(key))
6262
Object curValue = cur.get(key);
6363
if (!value.equals(curValue)) {
6464
// Work around for JSON serializer turning doubles/floats into ints since it drops ending 0's
65-
if (curValue instanceof Integer && !"".equals(value)) {
65+
if (curValue instanceof Number && value instanceof Number) {
6666
if ( ((Number)curValue).doubleValue() != ((Number)value).doubleValue())
6767
output.put(key, value);
6868
}

0 commit comments

Comments
 (0)