Skip to content
Advertisement

How to create a parent child Json response in Spring Boot with a Enum using Java

I am trying to create a json response from a Spring boot application where the name of the enum will be the parent structure and below that all the child will be residing . What i have created is showing only the child hierarchy but i want the parent also .Like i want below

JavaScript

what i am getting is

JavaScript

Below are codes what i have used

JavaScript

Advertisement

Answer

You are returning collection of the items, you need to return object with attribute items that will contain the collections.

This can be accomplished with Map.

JavaScript

If you are on Java9 or beyond you can do

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