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

IBM Cloud Mobile Services - Server side Java SDK for IBM Cloud Push Notifications Service
Apache License 2.0
3 stars 6 forks source link

NotificationBuilder throws JSON exception #17

Closed adnans-coviot closed 6 years ago

adnans-coviot commented 7 years ago

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)

AnanthaKrish commented 7 years ago

@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);

adnans-coviot commented 7 years ago

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..

AnanthaKrish commented 7 years ago

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

adnans-coviot commented 7 years ago

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.

AnanthaKrish commented 7 years ago

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" } } }

ManavIBM commented 7 years ago

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