I inspected whole documentation and I saw that Im forced to use 2 types of objects :
and
Does it change a lot?
It seems to me the way to solve this:
1) I am creating a POJO that will look like Organization
String id;
String name;
String parentId;
and save them in HashMap <String [id], Organization>
2) Creates an OrganizationTree object and initializes an empty array in it with a length equal to the number of objects marked as "root"
2) I drop all root objects into OrganizationTree (previously changed their type to OrganizationSubtree) and remove them from the map.
3) I iterate around the map taking the first objects that point to root as the parent object from the map and removing them from the map and putting them in the parent table.
4) I iterate across the map like this until it's empty.
It seems to me the simplest, but also terrible in terms of efficiency. Every time I will have to search every object and every array in it and in every array - another object with arrays (it is not known how many layers, there can be hundreds) + every time i add another children I need to create new array and copy the old one - because at the beginning i dont know how many childrens may parent have