I am trying to write a mini recursive closure to solve parent child iteration. At some point, I need to check if other children exist before I recursively call this closure. I check with IF, but for some reason returns if always.
Code Update with Objects Included
Have a Json object that has a Parent Children structure (jsonArray is indicated in the code below)
[
{
"id": "1",
"name": "No Children" //And yet the if condition is true -> element.children
},
{
"id": "2",
"name": "Does not like Children either"
},
{
"id": "123",
"name": "Some Parent Element",
"children": [
{
"id": "123123",
"name": "NameWhatever"
},
{
"id": "123123123",
"name": "Element with Additional Children",
"children": [
{
"id": "123123123",
"name": "WhateverChildName"
},
{
"id": "12112",
"name": "NameToMap"
}
]
}
]
}
]
There is also an ArrayList object that has no identifiers and needs to extract them from the iteration in jsonArray. This is called elementToGetID, which I simplify:
["count": 2741,"value": "NameToMap" ], ["count": 133,"value": "OtherName" ]
Thetwo for loops were written some time ago, and I'm trying to write a recursive closure to go deeper into children
for(int i=0; i<elementsToGetID.size(); i++){
for(int j=0; j<jsonArray.size(); j++){
{ element ->
if(element.name == elementsToGetID[i].value){
elementsToGetID[i]["id"] = element.id
}
if (element.children) {
element.children.each {inst ->
log.info "Element to continue function " +inst
call(inst)
}
}
}(jsonArray[j])
}
}