In this question we see that children element can either be an array of additional data items or a boolean
I am using Java to create the data, store in a Data class and then convert to Json using Google Gson. But because children can be two different things I have represented this by having a variable kids in my Data that I use when I need to store as boolean. Then do a String replace on the resulting json to turn it into a children element.
But this hack is not very satisfactory and problematic (i.e if they have real data with content "kids") so what is the proper way to represent data with varying data types.
public class Data
{
private String id;
private String text;
private String icon;
private State state;
private boolean kids;
private List<Data> children = null;
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getText()
{
return text;
}
public void setText(String text)
{
this.text = text;
}
public String getIcon()
{
return icon;
}
public void setIcon(String icon)
{
this.icon = icon;
}
public List<Data> getChildren()
{
return children;
}
public void setChildren(List<Data> children)
{
this.children = children;
}
public State getState()
{
return state;
}
public void setState(State state)
{
this.state = state;
}
public boolean getKids()
{
return kids;
}
public void setKids(boolean kids)
{
this.kids = kids;
}
}
public static String createFolderJsonData()
{
CreateFolderTree cft = new CreateFolderTree(null);
String treeData = cft.start(1).replace("kids", "children");
return treeData;
}