2

I am trying to deserialize an array of array of Strings using ObjectMapper. The input has the following structure: [["key", "value"], ["Car", "1"], ["SUV", "1.1"]]

I have tried to de-serialize this by using the following method:

JavaType itemType = objectMapper.getTypeFactory().constructCollectionType(List.class, Array.class);
List<T> mutableList = objectMapper.readValue(json.or("[]"), itemType);

However, the compiler complains of raw use of parameterized class. Could someone please explain how to serialize such an input ?

2
  • Are you using Jackson? Commented Feb 26, 2020 at 2:48
  • Yes. I'm using Jackson. The answer by Deadpool solves it. Commented Feb 26, 2020 at 19:09

1 Answer 1

1

The JSON you have is an Array with Array of string object and error message indicates to specify the exact type, so I would suggest to use TypeReference with exact type

List<List<String>> listCar = objectMapper.readValue(json.or("[]"), new TypeReference<List<List<String>>>(){});
Sign up to request clarification or add additional context in comments.

1 Comment

Much appreciated ! - Thanks

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.