Quantcast

Domain as JSON not serialising ID?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Domain as JSON not serialising ID?

Miles
Hey guys,

I've newed up a domain object like so:

User user = new User(id:'1', name: 'miles')

then within a controller:

request.withFormat {
xml { user as XML}
json { user as JSON }
}

Yet for some reason ID isn't serialised? Any one have any ideas?


--
Many thanks,
Miles Burton
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Domain as JSON not serialising ID?

burtbeckwith
The problem isn't with serialization - the constructor ignores id and version attributes for security reasons. So you can set all other properties in the constructor and then set the id separately:

   User user = new User(name: 'miles')
   user.id = '1'

Burt

Miles Burton wrote
Hey guys,

I've newed up a domain object like so:

User user = new User(id:'1', name: 'miles')

then within a controller:

request.withFormat {
xml { user as XML}
json { user as JSON }
}

Yet for some reason ID isn't serialised? Any one have any ideas?


--
Many thanks,
Miles Burton
Loading...