Hi, I'd like to define a tree structure. Here's what I got so far.
DOMAIN CLASS
I think it works fine, but, with this class I want to generate a JSON like this:
JSON (I want):
Instead I'm getting this JSON:
What am I doing wrong?
DOMAIN CLASS
Code:
class Tree {
String text
Tree parent
static hasMany = [ children: Tree ]
static constraints = {
parent(nullable: true)
}
String toString(){
text
}
}
I think it works fine, but, with this class I want to generate a JSON like this:
JSON (I want):
Code:
{
"redInstanceList": [
{
"text": "Root",
"children": [
{
"text": "Parent 2",
"children": []
},
{
"text": "Parent 1",
"children": [
{
"text": "Child 1",
"children": []
}
]
}
]
}
],
"success": true
}
Instead I'm getting this JSON:
Code:
{
"redInstanceList": [
{
"text": "Root",
"children": [
{
"text": "Parent 2",
"children": []
},
{
"text": "Parent 1",
"children": [
{
"text": "Child 1",
"children": []
}
]
}
]
},
{
"text": "Parent 1",
"children": [
{
"text": "Child 1",
"children": []
}
]
},
{
"text": "Parent 2",
"children": []
},
{
"text": "Child 1",
"children": []
}
],
"success": true
}
What am I doing wrong?