ibm-bluemix-mobile-services/bms-pushnotifications-serversdk-java

NotificationBuilder throws JSON exception

Closed this issue · 6 comments

Code:
NotificationBuilder builder = new NotificationBuilder("You have a new event!");
builder.setTarget(null, null, null, topicArray)
.setGCMSettings("", false, null, NotificationBuilder.GCMPriority.HIGH,null,null);

Throws:
java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set;
at com.ibm.mobilefirstplatform.serversdk.java.push.NotificationBuilder.setTarget(NotificationBuilder.java:131)

@adnans-coviot Please check the topicArray values...

For example ,

PushNotifications.init("appid", "appsecret", PushNotifications.US_SOUTH_REGION); NotificationBuilder builder = new NotificationBuilder("This is the notification's text!"); builder.setTarget(null, null, null, new String[]{"tag1","tag2"}) .setGCMSettings("", false, null, NotificationBuilder.GCMPriority.HIGH,null,null);

Applied your version as below, still the same error.
builder.setTarget(null, null, null, new String[]{"coviot"})
.setGCMSettings("", false, null, NotificationBuilder.GCMPriority.HIGH,null,null);

Exception thrown here in NotificationBuilder class:
if(!target.keySet().isEmpty()) {
this.notification.put("target", target);
}

Looks like a JSON library version or SDK version issue..

SDK version is - 1.0.1... Json version is - 20160212... can you try them ?

SDK is already 1.0.1
I've tried with Json 20170516 and gives the same exception.
Can you show the final json format? I'll try to build it in custom code and call the rest api directly.

the final Json body is like this (for your case),

{ "message" : { "alert" : "This is the notification's text!" }, "target" : { "tagNames" : [ "coviot" ] }, "settings" : { "gcm" : { "delayWhileIdle" : false, "priority" : "HIGH" } } }

Also can you check once if by any chance you have multiple json libraries in your java build path.