Hierarchical JSON with tree structure - java

I have to make a tree like JSON structure with Java where I have a parent node with multiple children in it and so on. This is my code I have partially done this one but not completely successful to do it ..here is the output I need
{
"name": "Culture",
"children": [
{
"name": "Salary"
},
{
"name": "Work",
"children": [
{
"name": "Effort"
},
{
"name": "trust"
}
]
}
]
}
but what I am generating is
{"name":"Culture",[{"name":"Salary"},{"name":"Work"},{"name":"Effort"}],"name":"Work",[{"name":"Culture"},{"name":"Work"}]}
Here is my code:
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class ParentChildApp {
public static class EntryListContainer {
public List<Entry> children = new ArrayList<Entry>();
public Entry name;
}
public static class Entry {
private String name;
public Entry(String name) {
this.name = name;
}
}
public static void main(String[] args) {
EntryListContainer elc1 = new EntryListContainer();
elc1.name = new Entry("Culture");
elc1.children.add(new Entry("Salary"));
elc1.children.add(new Entry("Work"));
elc1.children.add(new Entry("Effort"));
EntryListContainer elc2 = new EntryListContainer();
elc2.name = new Entry("Work");
elc2.children.add(new Entry("Culture"));
elc2.children.add(new Entry("Work"));
ArrayList<EntryListContainer> al = new ArrayList<EntryListContainer>();
Gson g = new Gson();
al.add(elc1);
al.add(elc2);
StringBuilder sb = new StringBuilder("{");
for (EntryListContainer elc : al) {
sb.append(g.toJson(elc.name).replace("{", "").replace("}", ""));
sb.append(",");
sb.append(g.toJson(elc.children));
sb.append(",");
}
String partialJson = sb.toString();
if (al.size() > 1) {
int c = partialJson.lastIndexOf(",");
partialJson = partialJson.substring(0, c);
}
String finalJson = partialJson + "}";
System.out.println(finalJson);
}
}

Do this:
package stackoverflow.questions;
import com.google.gson.*;
import java.util.ArrayList;
import java.util.List;
public class ParentChildApp {
public static class Entry {
private String name;
public Entry(String name) {
this.name = name;
}
private List<Entry> children;
public void add(Entry node){
if (children == null)
children = new ArrayList<Entry>();
children.add(node);
}
}
public static void main(String[] args) {
Entry workNode = new Entry("Work");
workNode.add(new Entry("Effort"));
workNode.add(new Entry("Trust"));
Entry salaryNode = new Entry("Salary");
Entry cultureNode = new Entry("Culture");
cultureNode.add(salaryNode);
cultureNode.add(workNode);
Gson g = new Gson();
System.out.println(g.toJson(cultureNode));
}
}
You will get exactly the JSON you are looking for.

Related

How to use json object name as an incremental value?

I'm quite new in JSON, I need a specific format of output JSON from Jackson API. Here is the output actually needed:
{
"0": {
"symbol": "B",
"count": 2,
"symbolIndex": [0, 0]
},
"1": {
"symbol": "B",
"count": 2,
"symbolIndex": [0, 0]
},
"2": {
"symbol": "B",
"count": 2,
"symbolIndex": [0, 0]
}
}
Consider that object names can vary (0,1,2,3,4,5....) and depends on the requirement and these can be only in incremental order. How can I use object to generate this JSON output in Java using Jackson API?
Update
So I have got the answer from Tom and the complete code is following:
MainClass.java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class MainClass {
public static void main(String[] args) {
SymbolCounts symbolCounts = new SymbolCounts();
symbolCounts.add("0", new MySymbol("A", 2, new int[]{1,1}));
symbolCounts.add("1", new MySymbol("B", 2, new int[]{1,1}));
symbolCounts.add("2", new MySymbol("C", 2, new int[]{1,1}));
String str = getJSONResponse(symbolCounts);
System.out.println(str);
}
protected static String getJSONResponse(SymbolCounts responseData) {
String jsonStringResponse = "";
try {
ObjectMapper mapper = new ObjectMapper();
jsonStringResponse = mapper.writeValueAsString(responseData);
} catch (JsonProcessingException jsonProcessingException) {
System.out.println(jsonStringResponse);
}
return jsonStringResponse;
}
}
SymbolCounts.java
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
#JsonInclude(NON_NULL)
#JsonIgnoreProperties(ignoreUnknown=true)
public class SymbolCounts {
#JsonProperty("symbolCounts")
private Map<String, MySymbol> symbolMap = new HashMap<String, MySymbol>();
#JsonAnySetter
public void add(String key, MySymbol value) {
symbolMap.put(key, value);
}
public Map<String, MySymbol> getSymbolMap() {
return symbolMap;
}
public void setSymbolMap(Map<String, MySymbol> symbolMap) {
this.symbolMap = symbolMap;
}
#Override
public String toString() {
return "SymbolCounts{" +
"symbolMap=" + symbolMap +
'}';
}
}
MySymbol.java
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Arrays;
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
#JsonInclude(NON_NULL)
#JsonIgnoreProperties(ignoreUnknown=true)
public class MySymbol {
private String symbol;
private int count;
private int[] symbolIndex;
public MySymbol() {
}
public MySymbol(String symbol, int count, int[] symbolIndex) {
this.symbol = symbol;
this.count = count;
this.symbolIndex = symbolIndex;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int[] getSymbolIndex() {
return symbolIndex;
}
public void setSymbolIndex(int[] symbolIndex) {
this.symbolIndex = symbolIndex;
}
#Override
public String toString() {
return "LineID{" +
"symbol='" + symbol + '\'' +
", count=" + count +
", symbolIndex=" + Arrays.toString(symbolIndex) +
'}';
}
}
You could do this by using a map and the #JsonAnySetter.
Your higher level class would look like:
private Map<String, MySymbol> symbolMap;
#JsonAnySetter
public void add(String key, MySymbol value) {
symbolMap.put(key, value);
}
Your MySymbol class would just be:
private String symbol;
private Integer count;
private Integer[] symbolIndex;
Then your end result would be a map where the keys are your numeric values as Strings and the values are your symbol objects.

com.google.gson.JsonSyntaxException:Expected STRING but was BEGIN_ARRAY

Kindly help me to get the subnodes list inside bom attributes
JSON file
[
{
"subConfigId":"bac",
"totalPrice":"634.00",
"bom":{
"ucid":"ucid",
"type":"RootNode",
"attributes":{
"visible":true,
"price_status":"SUCCESS"
},
"subnodes":[
{
"description":"Enterprise Shock Rack",
"ucid":"ucid"
},
{
"description":"SVC",
"ucid":"ucid"
}
]
},
"breakdown":{
"SV":550.0,
"HW":6084.0
},
"currency":"USD"
}
]
GsonNodes.java
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
public class GsonNodes {
public static void main(String[] args) throws IOException {
try{
JsonElement je = new JsonParser().parse(new FileReader(
"C:/Desktop/json.txt"));
JsonArray ja = je.getAsJsonArray();
Iterator itr = ja.iterator();
while(itr.hasNext()){
JsonElement je1 = (JsonElement) itr.next();
Gson gson = new Gson();
Details details = gson.fromJson(je1, Details.class);
System.out.println(details.getSubConfigId());
System.out.println(details.getCurrency());
System.out.println(details.getBreakdown());
System.out.println(details.getTotalPrice());
System.out.println(details.getBom().getUcid());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Details.java POJO
import java.io.Serializable;
import java.util.Map;
public class Details implements Serializable{
private String subConfigId;
private String totalPrice;
private Bom bom;
private String currency;
private Map<String, String> breakdown;
public String getSubConfigId() {
return subConfigId;
}
public void setSubConfigId(String subConfigId) {
this.subConfigId = subConfigId;
}
public String getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(String totalPrice) {
this.totalPrice = totalPrice;
}
public Bom getBom() {
return bom;
}
public void setBom(Bom bom) {
this.bom = bom;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public Map<String, String> getBreakdown() {
return breakdown;
}
public void setBreakdown(Map<String, String> breakdown) {
this.breakdown = breakdown;
}
}
Bom.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Bom implements Serializable{
private String ucid;
private String type;
private Map<String, String> attributes;
private List<Subnodes> subnodes = new ArrayList<Subnodes>();
public String getUcid() {
return ucid;
}
public void setUcid(String ucid) {
this.ucid = ucid;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
#Override
public String toString(){
return getUcid() + ", "+getType()+", "+getAttributes();
}
}
Subnodes.java
import java.io.Serializable;
import java.util.Map;
public class Subnodes implements Serializable{
private String description;
private String ucid;
private Map<String, String> attributes;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUcid() {
return ucid;
}
public void setUcid(String ucid) {
this.ucid = ucid;
}
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
}
I am getting an error , when i try to get the "subnodes"
I added the following code in the class
private List<Subnodes> subnodes = new ArrayList<Subnodes>();
then i am getting the error "Expected STRING but was BEGIN_ARRAY"
kindly help me that how can i get the "subnodes" list
In Bom.java
Please add a getter/setter method for :
private List<Subnodes> subnodes = new ArrayList<Subnodes>();
public List<Subnodes> getSubnodes() {
return subnodes;
}
public void setSubnodes(List<Subnodes> subnodes) {
this.subnodes = subnodes;
}
i have tried as below .. this is working fine.
package com.brp.mvc.util;
import java.io.IOException;
import java.util.Iterator;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
public class GsonNodes {
public static void main(String[] args) throws IOException {
try {
JsonElement je = new JsonParser().parse("[{\"subConfigId\":\"bac\",\"totalPrice\":\"634.00\",\"bom\":{\"ucid\":\"ucid\",\"type\":\"RootNode\",\"attributes\":{\"visible\":true,\"price_status\":\"SUCCESS\"},\"subnodes\":[{\"description\":\"Enterprise Shock Rack\",\"ucid\":\"ucid\"},{\"description\":\"SVC\",\"ucid\":\"ucid\"}]},\"breakdown\":{\"SV\":550.0,\"HW\":6084.0},\"currency\":\"USD\"}]");
JsonArray ja = je.getAsJsonArray();
Iterator itr = ja.iterator();
while (itr.hasNext()) {
JsonElement je1 = (JsonElement) itr.next();
Gson gson = new Gson();
Details details = gson.fromJson(je1, Details.class);
System.out.println(details.getSubConfigId());
System.out.println(details.getCurrency());
System.out.println(details.getBreakdown());
System.out.println(details.getTotalPrice());
System.out.println(details.getBom().getUcid());
System.out.println(details.getBom().getSubnodes().get(0).getDescription());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
i have added one method to convert json into string as below :
public static String readFile(String filename) {
String result = "";
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
line = br.readLine();
}
result = sb.toString();
} catch(Exception e) {
e.printStackTrace();
}
return result;
}
and use this method like below :
JsonElement je = new JsonParser().parse(readFile("C:/Desktop/json.txt"));

How to iterate over json data with gson

My json string is:
{
"recordsTotal":1331,
"data":[
{
"part_number":"3DFN64G08VS8695 MS",
"part_type":"NAND Flash",
"id":1154,
"manufacturers":[
"3D-Plus"
]
},
{
"part_number":"3DPM0168-2",
"part_type":"System in a Package (SiP)",
"id":452,
"manufacturers":[
"3D-Plus"
]
},
{
"part_number":"3DSD1G16VS2620 SS",
"part_type":"SDRAM",
"id":269,
"manufacturers":[
"3D-Plus"
]
}
]
}
This code lets me access the two highest level elements:
JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject();
System.out.println("data : " + jsonObject.get("data"));
System.out.println("recordsTotal : " + jsonObject.get("recordsTotal"));
But what I want to do is iterate over all the objects inside "data" and create a list of part_numbers. How do I do that?
JsonArray is an Iterable<JsonElement>. So you can use for in loop.
JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject();
final JsonArray data = jsonObject.getAsJsonArray("data");
System.out.println("data : " + data);
System.out.println("recordsTotal : " + jsonObject.get("recordsTotal"));
List<String> list = new ArrayList<String>();
for (JsonElement element : data) {
list.add(((JsonObject) element).get("part_number").getAsString());
}
Suppose class Name for Json Model is Example.
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class Example {
#SerializedName("recordsTotal")
private Integer recordsTotal;
#SerializedName("data")
private List<Datum> data = null;
public Integer getRecordsTotal() {
return recordsTotal;
}
public void setRecordsTotal(Integer recordsTotal) {
this.recordsTotal = recordsTotal;
}
public List<Datum> getData() {
return data;
}
public void setData(List<Datum> data) {
this.data = data;
}
}
And suppose List of Data class name is Datum :-
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class Datum {
#SerializedName("part_number")
private String partNumber;
#SerializedName("part_type")
private String partType;
#SerializedName("id")
private Integer id;
#SerializedName("manufacturers")
private List<String> manufacturers = null;
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
public String getPartType() {
return partType;
}
public void setPartType(String partType) {
this.partType = partType;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public List<String> getManufacturers() {
return manufacturers;
}
public void setManufacturers(List<String> manufacturers) {
this.manufacturers = manufacturers;
}
}
And then through Gson library we can convert json to java Model :
Example example = new Gson().fromJson(jsonString, new TypeToken<Example>() {}.getType());
Now we can get list of data though example model :-
List<Datum> dataList = example.getData();
From dataList you can traverse and get all info.
If partNmber List we need then we can get in this way :-
List<String> partNumberList = new ArrayList<>();
for (Datum data : dataList) {
partNumberList.add(data.getPartNumber());
}
The given code will not guaranteed to 100% equivalent but it will help you to work.
First you have to create the class for your data objects:
class mydata {
public String part_name;
public String part_type;
public int Id;
public String manufacturers;
}
Your main method should look like
public static void main(String[] args) {
JSONObject obj = new JSONObject();
List<mydata> sList = new ArrayList<mydata>();
mydata obj1 = new mydata();
obj1.setValue("val1");
sList.add(obj1);
mydata obj2 = new mydata();
obj2.setValue("val2");
sList.add(obj2);
obj.put("list", sList);
JSONArray jArray = obj.getJSONArray("list");
for(int ii=0; ii < jArray.length(); ii++)
System.out.println(jArray.getJSONObject(ii).getString("value"));
}
For futher exploration you can use that link:
https://gist.github.com/codebutler/2339666

create a customize json from servlet

I am new to json. I am able to create a json from servlet. But I am bounded to create a json like below-
{
"name":"Employee",
"children":[{
"name":"Subho"
},
{
"name":"jeet",
"children":[{
"name":"rahul"
},
{
"name":"abhijit"
}]
}]
}
But what I create is like-
{
"children":[
{"name":"Culture"},
{"name":"Salary"},
{"name":"Work"},
{"name":"Economy"}
],
"name":"Employee"
}
My servlet code is-
public class ActionServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Random r = new Random();
int low = 0;
int high = 5;
int R = r.nextInt(high - low) + low;
/*Sample data for child nodes actual data will be called here*/
String arr[] = {"Culture", "Salary", "Work", "Economy"};
/*Responsible for creation of the child nodes and their names */
Map<String, String> mapping = new HashMap<String, String>();
EntryListContainer entryListContainer = new EntryListContainer();
List<Entry> entryList1 = new ArrayList<Entry>();
for (int i = 0; i < R; i++) {
/*Model object for the Link*/
Entry entry1 = new Entry();
entry1.setChildren(arr[i]);
entryList1.add(entry1);
}
entryListContainer.setEntryList1(entryList1);
/*Root node this will collapse and get back to Original position on click*/
entryListContainer.setName("Employee");
mapping.put("entryList1","name");
Gson gson = new GsonBuilder().serializeNulls().setFieldNamingStrategy(new DynamicFieldNamingStrategy(mapping)).create();
System.out.println(gson.toJson(entryListContainer));
String json = null;
/*conversion of the json from the generated java object*/
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
json = new Gson().toJson(gson);
System.out.println(json);
response.getWriter().write(gson.toJson(entryListContainer));
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}
}
This is the EntryListContainer class
public class EntryListContainer {
private List<Entry> children;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setEntryList1(List<Entry> entryList1) {
this.children = entryList1;
}
public List<Entry> getEntryList1() {
return children;
}
This is the DynamicFieldNamingStrategy class
public class DynamicFieldNamingStrategy implements FieldNamingStrategy{
private Map<String, String> mapping;
public DynamicFieldNamingStrategy(Map<String, String> mapping) {
this.mapping = mapping;
}
#Override
public String translateName(Field field) {
String newName = mapping.get(field.getName());
if (newName != null) {
return newName;
}
return field.getName();
}
This servlet code is creating a json. Here 1st I create all the children nodes and put them in a list (here entryList1), and then put them in a hashmap. But what I create is not fulfilling my requirement..
Please anyone help me with this..
If we will put your JSon to jsoneditoronline, we get:
{
"name": "Employee",
"children": [
{
"name": "Subho"
},
{
"name": "jeet",
"children": [
{
"name": "rahul"
},
{
"name": "abhijit"
}
]
}
]
}
Now we can see that each Node has name and list of other Nodes:
Node
public class Node {
private String name = "";
private List<Node> children;
public List<Node> getChildren() {
return children;
}
public void setChildren(List<Node> children) {
this.children = children;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Code
Node child = new Node();
child.setName("Employee");
List<Node> list = new ArrayList<Node>();
Node subChild = new Node();
subChild.setName("Subho");
list.add(subChild);
subChild = new Node();
subChild.setName("jeet");
List<Node> sublist = new ArrayList<Node>();
Node subsubChild = new Node();
subsubChild.setName("Subho");
sublist.add(subsubChild);
subsubChild = new Node();
subsubChild.setName("Subho");
sublist.add(subsubChild);
subChild.setChildren(sublist);
list.add(subChild);
child.setChildren(list);
Gson gson = new Gson();
String output = gson.toJson(child);
Output:
{"name":"Employee","children":[{"name":"Subho"},{"name":"jeet","children":[{"name":"Subho"},{"name":"Subho"}]}]}

How to make a hirarchical tree structure Json using java program

I have to make a Json which will form a tree like structure.I have written a java code that is forming a structure like that but it does not satisfy the purpose.Here where i have done so far..This is my java class..
import com.google.gson.FieldNamingStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GsonProgram {
public static void main(String... args) throws Exception {
String arr[] = {"Culture", "Salary", "Work", "Effort"};
EntryListContainer entryListContainer = new EntryListContainer();
List<Entry> entryList1 = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
Entry entry1 = new Entry();
Entry entry2 = new Entry();
entry1.setChildren(arr[i]);
entryList1.add(entry1);
entryList2.add(entry2);
entryListContainer.setEntryList1(entryList1);
entryListContainer.setEntryList1(entryList2);
/*Root node this will collapse and get back to Original position on click*/
entryListContainer.setName("Employee");
entryListContainer.setName("manager");
}
Map<String, String> mapping = new HashMap<>();
mapping.put("entryList1", "name");
mapping.put("entryList2", "name");
Gson gson = new GsonBuilder().serializeNulls().setFieldNamingStrategy(new DynamicFieldNamingStrategy(mapping)).create();
System.out.println(gson.toJson(entryListContainer));
}
}
class DynamicFieldNamingStrategy implements FieldNamingStrategy {
private Map<String, String> mapping;
public DynamicFieldNamingStrategy(Map<String, String> mapping) {
this.mapping = mapping;
}
#Override
public String translateName(Field field) {
String newName = mapping.get(field.getName());
if (newName != null) {
return newName;
}
return field.getName();
}
}
class EntryListContainer {
private List<Entry> entryList1;
public void setEntryList1(List<Entry> entryList1) {
this.entryList1 = entryList1;
}
public List<Entry> getEntryList1() {
return entryList1;
}
}
class Entry {
private String name;
public String getChildren() {
return name;
}
public void setChildren(String name) {
this.name = name;
}
}
and this is the generated json
{
"name":[{
"name":"Salary"
},{
"name":"Salary"
},{
"name":"Work"
},{
"name":"Doller"
}]
}
But i want this structure...
{
"name":"Employee",
"children":[{
"name":"Salary"
},{
"name":"Salary"
},{
"name":"Work"
},{
"name":"Doller"
}]
}
I need this format of json.somebody please help....
The pseudo class structure should be:
class DynamicFieldNamingStrategy{
private String name;
private List<Entry> children;
}
GsonProgram
public class GsonProgram {
public static void main(String... args) throws Exception {
Entry entry1 = new Entry();
entry1.setChildren("Salary");
Entry entry2 = new Entry();
entry2.setChildren("Salary");
Entry entry3 = new Entry();
entry3.setChildren("Work");
Entry entry4 = new Entry();
entry4.setChildren("Doller");
EntryListContainer entryListContainer = new EntryListContainer();
ArrayList<Entry> entryList1 = new ArrayList<Entry>();
entryList1.add(entry1);
entryList1.add(entry2);
entryList1.add(entry3);
entryList1.add(entry4);
entryListContainer.setEntryList1(entryList1);
entryListContainer.setName("Employee");
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("entryList1", "name");
Gson gson = new GsonBuilder().serializeNulls().setFieldNamingStrategy(new DynamicFieldNamingStrategy(mapping)).create();
System.out.println(gson.toJson(entryListContainer));
}
}
EntryListContainer
class EntryListContainer {
private List<Entry> children;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setEntryList1(List<Entry> entryList1) {
this.children = entryList1;
}
public List<Entry> getEntryList1() {
return children;
}
}
Output:
{
"children": [
{
"name": "Salary"
},
{
"name": "Salary"
},
{
"name": "Work"
},
{
"name": "Doller"
}
],
"name": "Employee"
}

Categories