3

I have JSON response from Facebook, which I don't want to deserialize into a custom Java object. Mostly because there is no guarantee that their API will stay stable. Once they change it my deserialization will fail for sure.

What I want is to deserialize their JSON data into HashMap<String, Object>, where Object may be a String or a HashMap. In PHP it's called associative array and it is produced by json_decode() function. Is it possible to do the same in Java?

1 Answer 1

9

Certainly. Have a look at Jackson, it can do this easily enough, e.g.

ObjectMapper mapper = new ObjectMapper();
Map<String, Object> userData = mapper.readValue(jsonData, Map.class);

The resulting Map will nest as many levels deep as is required.

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.