ShipEngine / shipengine-java

The official Java SDK for ShipEngine API
https://www.shipengine.com/docs/
Apache License 2.0
1 stars 1 forks source link

API call error throw ClassCastException (should be ShipengineException) #19

Closed ducnh298 closed 2 years ago

ducnh298 commented 2 years ago

Your response return Map<String, String+ArrayList>:

unknown

In src/main/java/com/shipengine/InternalClient.java func checkResponseForErrors( ) you initiate a Map<String, ArrayList> to get that response:

11unk11nown

then this ClassCastException's always thrown (should be ShipengineException)

class java.lang.String cannot be cast to class java.util.ArrayList (java.lang.String and java.util.ArrayList are in module java.base of loader 'bootstrap')

Please help me solve this

AnneOReilly commented 2 years ago

@ducnh298 Thank you for raising this issue. We will review your PR and work to have this resolved.

ducnh298 commented 2 years ago

Hello there!

Looks like my PR doesn't solve anything (of course, my bad in checking back code) Is there any way to fix this issue, Or maybe the sandbox API key i'm using, its response is different from production.

Looking forward to hearing from you soon!

Best, Duc Nguyen Huu

sushithegreat commented 2 years ago

I believe you'll want to do this: List<Map<String, String>> result = shipengine.validateAddresses(unvalidatedAddress);

I've updated the readme as well, let me know if that does not resolve your issue.

ducnh298 commented 2 years ago

@sushithegreat No, it isn't my issue. You get it wrong. Please take a look at my first comment. I have 2 pics to describe it. I have issue in file "src/main/java/com/shipengine/InternalClient.java" at function "checkResponseForErrors( )"

sushithegreat commented 2 years ago

You should not be calling any of the methods in the InternalClient directly, only using methods in ShipEngine. What does your actual code look like?

ducnh298 commented 2 years ago

Yes I'm using methods in ShipEngine.

But when Shipengine meet error (such as incorrect address, carrier, service, etc...), I have to use debug mode, create a breakpoint in InternalClient to get the correct response. Otherwise, 100% times , this exception is thrown: "class java.lang.String cannot be cast to class java.util.ArrayList (java.lang.String and java.util.ArrayList are in module java.base of loader 'bootstrap')"

Which prevents me from getting specific error messages, to know what is wrong with my shipment details.

sushithegreat commented 2 years ago

I'm not able to reproduce this error. Can you post an example line of code?

ducnh298 commented 2 years ago

Does your error response look like this ? A map with String type key, but both String and ArrayList type value unknown

In src/main/java/com/shipengine/InternalClient.java func checkResponseForErrors( ) you initiate a Map<String, ArrayList> to get that response: 11unk11nown

String cannot be cast to ArrayList and this exception's throw: class java.lang.String cannot be cast to class java.util.ArrayList (java.lang.String and java.util.ArrayList are in module java.base of loader 'bootstrap')

sushithegreat commented 2 years ago

Fixed in #24

ducnh298 commented 2 years ago

Hi! Can you release new version maven's dependency (include this issue fixed) ?

sushithegreat commented 1 year ago

I'll publish a release ASAP, just waiting on some access control changes on our end

ducnh298 commented 1 year ago

Great, thanks!

Vào 5:10, Th 7, 22 thg 10, 2022 Susi Rathmann @.***> đã viết:

I'll publish a release ASAP, just waiting on some access control changes on our end

— Reply to this email directly, view it on GitHub https://github.com/ShipEngine/shipengine-java/issues/19#issuecomment-1287484553, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ6WI5XJN6POA4N6FZITHG3WEMIEDANCNFSM6AAAAAARBDORXA . You are receiving this because you were mentioned.Message ID: @.***>