From 0e7f591668046b530731edf940ac2341ab16b4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Tue, 5 May 2020 17:05:08 +0200 Subject: [PATCH] [expo-notifications] Fix crash when null value is passed in data --- .../notifications/NotificationSerializer.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java b/packages/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java index 80ac0e61b3674..c15cc8fd7191d 100644 --- a/packages/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java +++ b/packages/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java @@ -91,17 +91,15 @@ private static Bundle toBundle(@Nullable JSONObject notification) { Iterator keyIterator = notification.keys(); while (keyIterator.hasNext()) { String key = keyIterator.next(); - try { - Object value = notification.get(key); - if (value instanceof JSONObject) { - notificationMap.put(key, toBundle((JSONObject) value)); - } else if (value instanceof JSONArray) { - notificationMap.put(key, toList((JSONArray) value)); - } else if (value != null) { - notificationMap.put(key, value); - } - } catch (JSONException e) { - Log.e("expo-notifications", "Could not serialize whole notification - dropped value for key " + key + ": " + notification.opt(key)); + Object value = notification.opt(key); + if (value instanceof JSONObject) { + notificationMap.put(key, toBundle((JSONObject) value)); + } else if (value instanceof JSONArray) { + notificationMap.put(key, toList((JSONArray) value)); + } else if (JSONObject.NULL.equals(value)) { + notificationMap.put(key, null); + } else { + notificationMap.put(key, value); } } return new MapArguments(notificationMap).toBundle();