0

I have a requirement to deserialize Json object. The fields of incoming Json can change dynamically so I am thinking of storing it as a String. But not sure how to achieve this using Jackson. After deserializing the json I would want to access all the fields.

Incoming Json sample 1:

 {
    "NAME": "abs",
    "AGE": "25",
    "MARRIED": true,
}

Incoming Json sample 2:

 {
    "EMPLOYEE": true,
    "EMPLOYEEID": "123",
    "PERMANENT": true,
}

1 Answer 1

0

Read them into a node tree like in the following example, where input is a string containing your json:

ObjectMapper om = new ObjectMapper();
JsonNode node = om.readTree(input);

This allows you to access the fields of the json object dynamically, e.g.:

String name = node.path("NAME").asText();
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.