1

I have a JSON below that I'm trying to parse to a POJO using Jackson

{
    "Response": {
        "userIds": [
            "http://example.com:10249/User/526241869918679991"
        ],
        "userGroupIds": [
            "http://example.com:10249/UserGroup/1056659494710887089"
        ],
        "accountIds": [
            "http://example.com:10249/ServiceAccount/3354613317986071030"
        ],
        "success": true
    }
}

My Response POJO snippet is as below

private boolean success;
private List<String> accountIds;
private List<String> userIds;
private List<String> userGroupIds;

and their getter and setters

Is my declaration wrong as I'm getting "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token" error on parse"

The parse logic is as below:

jsonMapper.readValue(responseJSONString, new TypeReference<List<Response>>() {});

Any idea where I'm making the mistake?

1 Answer 1

3

First of all, your input starts with "Response": ... which must correspond to a field in some object. So what you have there is a json representation of a Response container:

class ResponseContainer {
    Response Response;
}

Secondly, your try to parse a list but your input doesn't start with [ (which lists should start with) but { which indicates that it's an object. So if you want it to be a list, wrap the input in [ ... ]:

So either change your input to be a list:

|
V

[
    {
        "Response": {
            "userIds": [
                "http://example.com:10249/User/526241869918679991"
            ],
            "userGroupIds": [
                "http://example.com:10249/UserGroup/1056659494710887089"
            ],
            "accountIds": [
                "http://example.com:10249/ServiceAccount/3354613317986071030"
            ],
            "success": true
        }
    }
]

^
|
Sign up to request clarification or add additional context in comments.

2 Comments

Your JSON array is an array of response containers, not an array of responses.
Wops. Thanks. I'll revise.

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.