Converted POJO classes to JSON using Jackson.
String jsonInString = mapper.writeValueAsString(Table 1);
I've JSON like below
{
"id": #,
"name":"name",
"Table 2":[
{
"id": #,
"name":"name",
"Table 3":[
{
"id": #,
"name":"name"
}
],
"Table 4":[
{
"id": #,
"name":"name"
}
]
},
{
"id": #,
"name":"name"
}
]
}
But I want JSON like
{
"TableName":"Table 1"
"id": #,
"name":"name",
"children":[
{
"TableName":"Table 2"
"id": #,
"name":"name",
"children":[
{
"TableName":"Table 3"
"id": #,
"name":"name"
},
{
"TableName":"Table 4"
"id": #,
"name":"name"
}
]
},
{
"TableName":"Table 2"
"id": #,
"name":"name"
}
]
}
How do I can edit format of json like this? Thanks in advance..
My POJO class structure is like
Table 1.java
@JsonProperty("children")
private Set<Table2> Table2 = new HashSet<Table2>(0);
Table 2.java
@JsonProperty("children")
private Set<Table1> Table1 = new HashSet<Table1>(0);
//@JsonProperty("children")
private Set<Table3> Table3 = new HashSet<Table3>(0);
//@JsonProperty("children")
private Set<Table4> Table4 = new HashSet<Table4>(0);
Table 3.java
@JsonProperty("children")
private Set<Table2> Table2 = new HashSet<Table2>(0);
Table 4.java
@JsonProperty("children")
private Set<Table2> Table2 = new HashSet<Table2>(0);
In Table 2.java, I want Table3 & Table4 under Children. But I cant use @JsonProperty("children") for both Table3 & Table4, they will be conflict between names.
"children":[
{
"TableName":"Table 3"
"id": #,
"name":"name"
},
{
"TableName":"Table 4"
"id": #,
"name":"name"
}
]
How we need to create Table 2.java POJO class here ?
Creating right POJO would solve your problem. You can create POJO like shown below