I have a JSON file which have separate subsections and all the subsections have same type of data, is there any way we can directly map these inner objects
{
"pre-execution": {
"nodes": [],
"links": []
},
"execution": {
"nodes": [],
"links": []
},
"completion": {
"nodes": [],
"links": []
}
}
I am interested only in node and link type of data and not bothered about from which category it belongs to.
My class structure looks like this
public class NodeElement{
private List<Node> nodes;
private List<Link> links;
}
Is there any way i can directly map it through Gson library. The code i am using is giving null
Gson gson=new Gson();
NodeElement nodeElements=gson.fromJson(jsonString,NodeElement.class);
the reason i got because it is not following the correct hierarchy. The point is I am interested in only Node
and Link
so why should worry for the hierarchy.
Any other library can be used if not Gson?
i tried doing this way
for(Map.Entry<String,JsonElement> entry : entrySet){
if(entry.getKey().contains("node")){
siteFlowElement.addNodes((List<GoJSNode>) obj.get(entry.getKey()));
}
if(entry.getKey().contains("link")){
siteFlowElement.addLinks((List<GoJSLink>) obj.get(entry.getKey()));
}
}
System.out.println("Nodes"+siteFlowElement.getNodes());
System.out.println("Links"+siteFlowElement.getLinks());
But it is returning null,
Json object is populating fine