Filipe_Madelino | 2017-10-19 02:03:54 UTC | #1
Hi,
Using the Java SDK we setup a notification handle to handle the routing status events... but we are getting the following error:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "id" (class com.mypurecloud.sdk.v2.model.UserRoutingStatusNotification), not marked as ignorable (2 known properties: "routingStatus", "errorInfo"]) at [Source: {"topicName":"v2.users.8c6687ff-ea8d-4275-9d4d-3d160f8a0a1f.routingStatus","version":"2","eventBody":{"id":"8c6687ff-ea8d-4275-9d4d-3d160f8a0a1f","routingStatus":{"status":"IDLE","startTime":"2017-10-19T01:14:04.735Z"}},"metadata":{"CorrelationId":"341cedc9-8110-4e51-b2b1-0f93b0af5c2d"}}; line: 1, column: 109] (through reference chain: com.mypurecloud.sdk.v2.extensions.notifications.NotificationEvent["eventBody"]->com.mypurecloud.sdk.v2.model.UserRoutingStatusNotification["id"])
From our analysis the JSON payload is something like:
{ "id": "8c6687ff-ea8d-4275-9d4d-3d160f8a0a1f", "routingStatus": { "status": "OFF_QUEUE", "startTime": "2017-10-19T01:49:02.959Z" } }
but the class used to be set with the JSON payload is UserRoutingStatusNotification... which doesn't have the field member id...
My question are we using the correct class (UserRoutingStatusNotification) to set the JSON payload into?
We are using SDK v19
Regards Filipe Madelino
Filipe_Madelino | 2017-10-19 02:36:54 UTC | #2
Some updates...
So we manage to fix this by changing the NotificationHandler (which comes with the SDK) setting up on the Jackson mapper a configuration parameter:
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAILONUNKNOWN_PROPERTIES, false);
(see link http://www.baeldung.com/jackson-deserialize-json-unknown-properties for details in terms of the Jackson lib config)
But we went to this path as we had before to make our "own" notification handler due to the fact that the default one (on SDK) doesn't support Proxy settings (for which we already raise a forum post)....
Anyway I think the SDK should consider the class for the notification event body in sync with the JSON payload structure.
Regards Filipe Madelino
tim.smith | 2017-10-23 14:46:57 UTC | #3
Are you using platform-client-v2 v21.0.0? I tested this version with the following code and it works without issue.
package com.genesys;
import com.mypurecloud.sdk.v2.ApiClient;
import com.mypurecloud.sdk.v2.Configuration;
import com.mypurecloud.sdk.v2.api.UsersApi;
import com.mypurecloud.sdk.v2.extensions.notifications.NotificationHandler;
import com.mypurecloud.sdk.v2.model.UserMe;
import com.mypurecloud.sdk.v2.extensions.notifications.NotificationEvent;
import com.mypurecloud.sdk.v2.extensions.notifications.NotificationListener;
import com.mypurecloud.sdk.v2.model.UserRoutingStatusNotification;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
try {
String accessToken = "mytoken";
ApiClient apiClient = ApiClient.Builder.standard()
.withAccessToken(accessToken)
.withBasePath("https://api.mypurecloud.com")
.build();
// Use the ApiClient instance
Configuration.setDefaultApiClient(apiClient);
UsersApi usersApi = new UsersApi();
UserMe me = usersApi.getUsersMe(new ArrayList<>());
NotificationHandler notificationHandler = NotificationHandler.Builder.standard()
.withNotificationListener(new UserRoutingStatusNotificationListener(me.getId()))
.withAutoConnect(false)
.build();
// Wait for the user to press enter before exiting
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Press enter to exit...");
String input = br.readLine();
System.out.println("Done " + input);
// Exit application successfully
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class UserRoutingStatusNotificationListener implements NotificationListener<UserRoutingStatusNotification> {
private String topic;
public String getTopic() {
return topic;
}
public Class<UserRoutingStatusNotification> getEventBodyClass() {
return UserRoutingStatusNotification.class;
}
public void onEvent(NotificationEvent<?> event) {
System.out.println("routing status -> " + ((UserRoutingStatusNotification)event.getEventBody()).getRoutingStatus().getStatus());
System.out.println("routing status -> " + event.getEventBodyRaw());
}
public UserRoutingStatusNotificationListener(String userId) {
this.topic = "v2.users." + userId + ".routingStatus";
}
}
system | 2017-11-23 14:47:00 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 1972