@SuppressWarnings("unchecked")
private static TreeNode build(Object value) {
TreeNode treeNode;
if (value instanceof Map<?, ?>) {
TreeBranch treeBranch = new TreeBranch("{}");
Map<String, Object> map = (Map<String, Object>)value;
for (String key : map) {
TreeNode valueNode = build(map.get(key));
String text = valueNode.getText();
if (text == null) {
valueNode.setText(key);
} else {
valueNode.setText(key + " : " + text);
}
treeBranch.add(valueNode);
}
treeNode = treeBranch;
} else if (value instanceof List<?>) {
TreeBranch treeBranch = new TreeBranch("[]");
List<Object> list = (List<Object>)value;
for (int i = 0, n = list.getLength(); i < n; i++) {
TreeNode itemNode = build(list.get(i));
String text = itemNode.getText();
if (text == null) {
itemNode.setText("[" + i + "]");
} else {
itemNode.setText("[" + i + "] " + text);
}
treeBranch.add(itemNode);
}
treeNode = treeBranch;
} else if (value instanceof String) {
treeNode = new TreeNode("\"" + value.toString() + "\"");