In my application, domain classes are added as grails plugin. The controller converts model object to JSON using :
ResultObj as JSON
But the generated JSON has properties(that are objects themselves) as the class name and id instead of its property values. Any advise is much appreciated.
The object structure looks similar to the following:
class Parent{
String property1
static hasMany = [property2:Child]
static constraints = {
}
}
class Child{
String property3
static belongsTo = [property4:Parent]
static constraints={}
}
Generated JSON looks like:
[{"class":"package.Parent","id":1, "property1":"value","property2":[{"class":"package.Child","id":1},{"class":"package.Child","id":2}]}]
The default fetch strategy used by Grails is "lazy", which means that the collection will be lazily initialized on first access. This can lead to the n+1 problem if you are not careful.
--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.
To post to this group, send email to grails-dev-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/c29ad118-2166-45e3-8f0b-1a513cba8ab1%40googlegroups.com.
--Sérgio Michels
To post to this group, send email to grails-de...@googlegroups.com.