mwkirk / javapns

Test import of svn javapns repo from Google Code
3 stars 0 forks source link

aps dictionary not automatically created #154

Open mwkirk opened 11 years ago

mwkirk commented 11 years ago

Original author: Scunderw...@gmail.com (November 13, 2012 21:11:12)

/* Construct a Payload object from a JSON-formatted string. * If an aps dictionary is not included, one will be created automatically. * @param rawJSON a JSON-formatted string (ex: {"aps":{"alert":"Hello World!"}} ) * @throws JSONException thrown if a exception occurs while parsing the JSON string / public PushNotificationPayload(String rawJSON) throws JSONException { super(rawJSON); try { JSONObject payload = getPayload(); this.apsDictionary = payload.getJSONObject("aps"); if (this.apsDictionary == null) { this.apsDictionary = new JSONObject(); payload.put("aps", this.apsDictionary); }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

This code will not create an aps dictionary if you pass it a simple "{}"; It just catches and prints the following exception, instead of throwing it so the caller can handle it. Its very misleading to throw the same type of exception that you swallow.

org.json.JSONException: JSONObject["aps"] not found. at org.json.JSONObject.get(JSONObject.java:496) at org.json.JSONObject.getJSONObject(JSONObject.java:579)

Original issue: http://code.google.com/p/javapns/issues/detail?id=154