Groovy Bean Requirements for json()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Groovy Bean Requirements for json()

Tim Stearn
Hi All,

Are there special requirements for Groovy beans to allow them to be converted to JSON?  I'm trying to send  a JSON response with an instance of the class below:

class User {
    String _id
    String firstName
    String lastName
    String email
    String gender
    String picLocation

    def Boolean validate(){
        def reqFieldsPresent = firstName && lastName && email
        def isValid = reqFieldsPresent && (!gender || ['M','F'].contains(gender))
        if(!isValid) {
            throw new ValidationException()
        }
        return true;
    }
}

I get the following message if I pass this object to json():

groovy.lang.MissingMethodException: No signature of method: ratpack.json() is applicable for argument types: (com.stepchat.domain.User) values: [[email protected]]

I've also tried converting it to a map and then passing it to json(), but I get a similar error.

Thanks,

Tim S.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Bean Requirements for json()

Luke Daley
Administrator

You might have forgotten to static import Jackson.json().
Reply | Threaded
Open this post in threaded view
|

Re: Groovy Bean Requirements for json()

Tim Stearn

​Yes, that was it - thanks.


Tim Stearn
Principal Solutions Architect
SAS Institute Inc
(919)531-9332 (o)
(412)418-2688 (m)
[hidden email]
www.sas.com


From: Luke Daley [via Ratpack Forum] <ml-node+[hidden email]>
Sent: Sunday, June 7, 2015 8:06 PM
To: Tim Stearn
Subject: Re: Groovy Bean Requirements for json()
 

You might have forgotten to static import Jackson.json().



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Groovy-Bean-Requirements-for-json-tp1103p1104.html
To unsubscribe from Groovy Bean Requirements for json(), click here.
NAML