Skip to content
Advertisement

Parse JSON file with dynamic fields by java

How to parse JSON file with the object, which contains dynamic fields. As an example here: Here is “items”, which has objects with name(“1c68b853-2a07-4409-ad61-8650212f3260”) and body. And it’s more then 2 items.

JavaScript

Advertisement

Answer

You can easily use the Map interface, to store the dynamic parts:

Root.java:

JavaScript

Item.java:

JavaScript

MappingTest.java:

JavaScript

You can also, as well, create three different classes for name, modifiedDate, id, but this is enough to show the main idea of the answer.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement