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,
}
PVJ
  • 79
  • 3
  • 9

1 Answers1

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();
Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60