Skip to content
Advertisement

Mapping nested JSON values in a Java class

I can’t figure out how to handle nested JSON values in my Java classes. To make it simple as possible, I created four Java classes with every ‘nested level’. However, I’m trying to have all these values in one Java class. How can I do this?

Json:

JavaScript

Java classes:

JavaScript

Advertisement

Answer

You can club all the supporting classes in one class like below :

JavaScript

You can test (I am using Jackson for deserialization)
create ObjectMapper class and deserialize into a Root class

JavaScript

-When debugging, you’ll notice that our objects have been filled accordingly: enter image description here

**Changes done as per your requiement **

JavaScript

JavaScript

ebugging, you'll notice that our objects have been filled accordingly:

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