From 3a7bd9da5d27992f78e62df36d14b63516ebfdab Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 9 Apr 2015 02:00:33 +0800 Subject: [PATCH] hotfix for unsupported card entity --- .../internal/json/CardEntityJSONImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java b/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java index dc78c32cb..15a1caefb 100644 --- a/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java +++ b/twidere.component.twitter4j/src/main/java/twitter4j/internal/json/CardEntityJSONImpl.java @@ -96,8 +96,8 @@ public class CardEntityJSONImpl implements CardEntity { return type; } - private static BindingValue valueOf(String name, JSONObject json) throws JSONException { - final String type = json.optString("type"); + private static BindingValue valueOf(String name, JSONObject json) throws JSONException, TwitterException { + final String type = json.getString("type"); if (TYPE_STRING.equals(type)) { return new StringValueImpl(name, json); } else if (TYPE_IMAGE.equals(type)) { @@ -107,15 +107,17 @@ public class CardEntityJSONImpl implements CardEntity { } else if (TYPE_BOOLEAN.equals(type)) { return new BooleanValueImpl(name, json); } - throw new UnsupportedOperationException(String.format("Unsupported type %s", type)); + throw new TwitterException(String.format("Unsupported type %s", type)); } - private static HashMap valuesOf(JSONObject json) throws JSONException { + private static HashMap valuesOf(JSONObject json) throws JSONException, TwitterException { final Iterator keys = json.keys(); final HashMap values = new HashMap<>(); while (keys.hasNext()) { - String key = keys.next(); - values.put(key, valueOf(key, json.getJSONObject(key))); + final String key = keys.next(); + if (!json.isNull("name")) { + values.put(key, valueOf(key, json.getJSONObject(key))); + } } return values; }