What steps will reproduce the problem?
public class JSonNode {
private String label;
private String identifier;
private List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
}
I have remove get set methods for simplicity.
public static void main(String [] args ) {
JSonNode node= new JSonNode();
Gson g = new Gson();
node.setIdentifier("name");
node.setLabel("name");
Map<String, Object> values = new HashMap<String, Object>();
values.put("name", "Africa");
values.put("type", "continent");
List<JSonNode> children = new ArrayList<JSonNode>();
JSonNode child1 = new JSonNode();
Map<String, Object> values1 = new HashMap<String, Object>();
values1.put("name", "Egypt");
values1.put("type", "country");
child1.getItems().add(values1);
JSonNode child2 = new JSonNode();
values1 = new HashMap<String, Object>();
values1.put("name", "Kenya");
values1.put("type", "country");
child2.getItems().add(values1);
JSonNode child3 = new JSonNode();
values1 = new HashMap<String, Object>();
values1.put("name", "Sudan");
values1.put("type", "country");
child3.getItems().add(values1);
children.add(child1);
children.add(child2);
children.add(child3);
values.put("children", children);
node.getItems().add(values);
System.out.println(g.toJson(node));
}
What is the expected output? What do you see instead?
Expected O/P :
{"label":"name","identifier":"name","items":[{"name":"Africa","children":{"name"
:"Africa","children":[{"items":[{"name":"Egypt","type":"country"}]},{"items":[{"
name":"Kenya","type":"country"}]},{"items":[{"name":"Sudan","type":"country"}]}]
,"type":"continent"},"type":"continent"}]}
Acutal O/P :
{"label":"name","identifier":"name","items":[{"name":"Africa","children":{},"typ
e":"continent"}]}
What version of the product are you using? On what operating system?
Gson 1.5, Windows, with JDK 1.5
Please provide any additional information below.
Original issue reported on code.google.com by nis...@gmail.com on 30 Sep 2010 at 10:56
Original issue reported on code.google.com by
nis...@gmail.com
on 30 Sep 2010 at 10:56