0

Here is a sample json:

{"LIST_OF_IDS_FOR_RETRANSFER":["50, 39, 29"]}

Now I'm trying to parse this json to map with no luck:

Map<String, List<Integer>> params = new ObjectMapper().readValue(jsonString, new TypeReference<Map<String, List<Integer>>>(){});

The result is the Map with one entry:

key: LIST_OF_IDS_FOR_RETRANSFER

value: List with size=1, value is '50, 39, 29'.

But I want to get List with size=3. Is it possible to achieve with Jackson?

1
  • 5
    Well you are quite literally trying to parse an array consisting of a single string "50, 39, 29". Did you mean: {"LIST_OF_IDS_FOR_RETRANSFER":[50, 39, 29]}? If not, you can simply split the LIST_OF_IDS_FOR_RETRANSFER on , to extract the ids. Commented May 4, 2018 at 15:12

1 Answer 1

2

Since your type reference is Map<String, List<Integer>>, then your JSON should look like this: {"LIST_OF_IDS_FOR_RETRANSFER":[50, 39, 29]} (remove the "" around the numbers).

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.