0

I have a string like this

"{
    "scanReference": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "document": {
        "status": "data",
        "data": {
            "firstName": "FULL NAME",
            "info": "{\"city\":\"CITY\",\"issueDate\":\"2019-01-01\"}"
        },
        "country": "USA"
    }
}"

I have created class (simple POJO) to convert this to java object and using GSON. I am using the below code to convert to java object.

(gson.fromJson(response, MyClass.class));

But I am receiving the below error when converting , it because "info" is a string not json.

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING

The code works as expected when I made "info" a json and tested it, but it is string here.

Can anyone help me to solve this problem?

PS: Thank you for help.

1 Answer 1

1

Create info class within MyClass.

Public class MyClass.class{
private String scanReference;
..........
private Info info

//Setter getter
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.