In this post, we will see how to resolve How to deserialize String to java Instant
Question:
I have a a JSON string as :String
to MyResponse
as :expireAt
field:Expected BEGIN_OBJECT but was STRING at line 1 column 24 path $.details[0].expireAt
How can I resolve this ?
Best Answer:
The exception you’re getting is because the “expireAt” field in the JSON is a string, but in the Details class it’s declared as an Instant type. You need to tell Gson how to convert the string to an Instant.You can create a custom Gson deserializer for the Instant type, like this:
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com