1

I am integrating the shipment in my application using easy post API when I use shipment.create(shipmentMap, EASYPOSTAPIKEY) it's throwing an error Expected a string but was BEGIN_OBJECT at line 1 column 123 path $.options.

Map<String, Object> parcelMap = new HashMap<String, Object>();
parcelMap.put("predefined_package", "FlatRateEnvelope");
parcelMap.put("weight", 10);
Parcel parcel = Parcel.create(parcelMap);
Map<String, Object> shipmentMap = new HashMap<String, Object>();
shipmentMap.put("to_address", toAddress);
shipmentMap.put("from_address", fromAddress);
shipmentMap.put("parcel", parcel);
Shipment shipment = Shipment.create(shipmentMap, EASYPOSTAPIKEY);

java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 123 path $.options.at com.google.gson.stream.JsonReader.nextString(JsonReader.java:825) ~[gson-2.8.5.jar:na]

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
  • I'm experiencing the same issue, but annoyingly it's only occuring in production. I narrowed the issue down to Gson failing to parse the Map options; object in the Shipment class. I will create an issue for this in the EasyPost GitHub – mharray Jul 07 '20 at 02:05
  • github issue: https://github.com/EasyPost/easypost-java/issues/54 – mharray Jul 07 '20 at 02:28

2 Answers2

0

I am not sure of Easy post API but from exception

options.at com.google.gson.stream.JsonReader.nextString(JsonReader.java:825) ~[gson-2.8.5.jar]

I could say it is related to GSON.

From my understanding GSON says it needs a String but there was an object.

referred this post for that. GSON throwing "Expected BEGIN_OBJECT but was BEGIN_ARRAY"?

I would ask you to go through the document again and check what you have missed

Avi
  • 1,458
  • 9
  • 14
0

Updating the latest version of easy post client API should fix this.

Hari Krishnan
  • 1,066
  • 2
  • 13
  • 31
  • I'm experiencing the same issue, but already have the latest version of the easy post client api – mharray Jul 07 '20 at 00:19