I am using some scaffolded services to load some existing domain classes. For some reason when the classes get serialized (JSON) the child objects appear empty. I can inspect them before the resource returns them to be serialized and get values (via log statements). It's very strange.
My parent class (Job) has two child classes - User and JobStatus. Neither are loaded correctly. In the code below the three log.error statements produce values. The final JSON shows nulls (it does serialize as the object with fields - just all are null). If I replace the jobStatus object as in the commented out line it will serialize values. I've also tried setting the hibernate mapping in Job.groovy to lazy: false. Seems like the job.jobStatus proxy is loaded according to everything except the serialization.
@Consumes(['application/xml','application/json'])
@Produces(['application/xml','application/json'])
class JobResource {
def jobResourceService
def id
@GET
Response read() {
def job = jobResourceService.read(id)
log.error job.user.username
log.error job.jobStatus
log.error job.jobStatus
ok job
}