EasyPost / easypost-java

EasyPost Shipping API Client Library for Java
https://easypost.com/docs/api
MIT License
53 stars 37 forks source link

[Bug]: IllegalStateException when deseralizing 'Payload' #246

Closed yasnmert closed 1 year ago

yasnmert commented 1 year ago

Software Version

6.3.0

Language Version

17

Operating System

Macos

What happened?

Hello,

the retrieve All Payloads and retrieve Payload methods added in version 6.2.0 give an error as follows.

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 552 path $.payloads[0].request_body

After my research, it seems that the error is caused by using the requestBody field in Payload class as a map. This field, which is expected as a map in the Payload class, comes as a String from the endpoint("events/" + eventId + "/payloads"). This situation is causing an exception.

When I call the endpoint with the following class example, returning a successful value;

@Data
public class CustomPayload extends EasyPostResource {
  private String requestUrl;
  private Map<String, String> requestHeaders;
  private String requestBody;
  private Map<String, String> responseHeaders;
  private String responseBody;
  private int responseCode;
  private int totalTime;
}

What was expected?

The data that will come from the endpoint should be json or the 'requestBody' field in the payload class should be defined as a string.

Sample Code

No response

Relevant logs

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 552 path $.payloads[0].request_body
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:395)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:431)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:391)
    at com.google.gson.Gson.fromJson(Gson.java:1214)
    at com.google.gson.Gson.fromJson(Gson.java:1124)
    at com.google.gson.Gson.fromJson(Gson.java:1034)
    at com.google.gson.Gson.fromJson(Gson.java:969)
    at com.easypost.http.Requestor.httpRequest(Requestor.java:580)
    at com.easypost.http.Requestor.request(Requestor.java:487)
    at com.easypost.http.Requestor.request(Requestor.java:438)
    at com.easypost.service.EventService.retrieveAllPayloads(EventService.java:63)
nwithan8 commented 1 year ago

Hello, thank you for pointing this out, and for the proposed fix!

On first look, it seems like this might have slipped through the cracks unfortunately. We'll investigate and try to get a patch out as soon as possible. We'll keep you updated!

yasnmert commented 1 year ago

Thank you

jchen293 commented 1 year ago

@yasnmert Thanks for reporting this again. I have made a PR #257 to fix this and we are expecting to make a release sometime next week😁

yasnmert commented 1 year ago

Thank you