Vonage / vonage-java-sdk

Vonage Server SDK for Java. API support for SMS, Messages, Voice, Text-to-Speech, Numbers, Verify (2FA), Video and more.
https://developer.vonage.com/en/home
Apache License 2.0
95 stars 119 forks source link

Cannot retrieve messages for given conversation : VonageResponseParseException! #536

Closed jerome25000 closed 1 week ago

jerome25000 commented 1 week ago

Hello, I am using the latest java SDK (8.9.0) Create a conversation with 2 members. : ok Add simple text message for the 2 members : ok Try to get all conversation : KO

Following java code :

public void listMessages(ConversationsClient client, String roomId) { ListEventsRequest request = ListEventsRequest.builder().eventType(EventType.MESSAGE).build(); ListEventsResponse response = client.listEvents(roomId, request);

Stacktrace Exception in thread "main" com.vonage.client.VonageResponseParseException: Failed to produce ListEventsResponse from JSON. at com.vonage.client.Jsonable.updateFromJson(Jsonable.java:82) at com.vonage.client.Jsonable.fromJson(Jsonable.java:128) at com.vonage.client.DynamicEndpoint.parseResponseSuccess(DynamicEndpoint.java:308) at com.vonage.client.DynamicEndpoint.parseResponse(DynamicEndpoint.java:244) at com.vonage.client.AbstractMethod.execute(AbstractMethod.java:82) at com.vonage.client.conversations.ConversationsClient.listEvents(ConversationsClient.java:363) at com.vonage.client.conversations.ConversationsClient.listEvents(ConversationsClient.java:348) at org.example.VonageConversationManager.listMessages(VonageConversationManager.java:74) at org.example.VonageConversationManager.main(VonageConversationManager.java:105) Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<com.vonage.client.conversations.Event> from Object value (token JsonToken.START_OBJECT) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 30] (through reference chain: com.vonage.client.conversations.ListEventsResponse["_embedded"])

The java response is not complient with the java

public final class ListEventsResponse extends HalPageResponse { @JsonProperty("_embedded") private List events;

ListEventsResponse() {
}

@JsonProperty("_embedded")
public List<Event> getEvents() {
    return this.events;
}

}

Should have a intermediate object embeded (having a event property) like this :

public final class ListEventsResponse extends HalPageResponse { @JsonProperty("_embedded") Embedded embedded;

ListEventsResponse() {}

@JsonProperty("_embedded")
public List<Event> getEvents() {
    return this.embedded.getEvents();
}

}

public class Embedded {

Embedded() {}

@JsonProperty("events")
private List<Event> events;

@JsonProperty("events")
public List<Event> getEvents() {
    return this.events;
}

}

fgtamburrodeb commented 1 week ago

Hello, I encountered the same issue with the latest Java SDK (8.9.0). The exception occurs when trying to list all conversation messages. For context, I also experienced the same problem with SDK version 8.6.0. Thank you.

SMadani commented 1 week ago

Thanks for raising this, will have this fixed in the next patch release.

SMadani commented 1 week ago

Fixed in v8.9.1, however please note many read-only events in the API are not currently supported, so you will have to query them manually through the getBody() method of GenericEvent, which provides a Map<String, ?> rather than native data structures. Support for events will be expanded in future releases.