Eddard Stark
Eddard Stark

Reputation: 3595

Convert JSON to grails object

I have a JSON object in my view page, I pass it via params, lets say 'params.userInfo' and in the controller, I want it to parse to an object 'User' which I have created. How do I do it ? The user object may be such

class User{
  string name
  string age
}

Thanks in advance

Upvotes: 3

Views: 5121

Answers (2)

Tomasz Kalkosiński
Tomasz Kalkosiński

Reputation: 3723

This should work:

def user = new User(params.userInfo)

Upvotes: 4

Tom Metz
Tom Metz

Reputation: 919

You can get the information from Grails documentation here: http://grails.org/Converters+Reference

Upvotes: 3

Related Questions