I want something like this in my application with json builder
new JsonBuilder() {
persons.collect{
[
name: it.name,
age: it.age,
companies: [{
company1: it.company //The company comes from person object.
},
{
company2: it.company
}
]
]
}
}
Here while accessing the company null pointer exception is being thrown as it is not considering the person iterator.Is there any other way to do it in this way??