Added Map and List support to JSON object stream
This commit is contained in:
parent
0dd8e7b415
commit
4a817cbf31
6 changed files with 139 additions and 50 deletions
|
|
@ -123,10 +123,22 @@ public class JSONObjectOutputStream extends OutputStream implements ObjectOutput
|
|||
root.set(field.getName(), arrayNode);
|
||||
}
|
||||
else if(List.class.isAssignableFrom(field.getType())){
|
||||
// TODO Add List Support
|
||||
DataNode listNode = new DataNode(DataNode.DataType.List);
|
||||
List list = (List)fieldObj;
|
||||
for(Object item : list){
|
||||
listNode.add(getDataNode(item));
|
||||
}
|
||||
root.set(field.getName(), listNode);
|
||||
}
|
||||
else if(Map.class.isAssignableFrom(field.getType())){
|
||||
// TODO Add Map Support
|
||||
DataNode mapNode = new DataNode(DataNode.DataType.Map);
|
||||
Map map = (Map)fieldObj;
|
||||
for(Object key : map.keySet()){
|
||||
mapNode.set(
|
||||
getDataNode(key).getString(),
|
||||
getDataNode(map.get(key)));
|
||||
}
|
||||
root.set(field.getName(), mapNode);
|
||||
}
|
||||
else{
|
||||
root.set(field.getName(), getDataNode(fieldObj));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue