0

My Grails app includes an action that expects the following JSON data to be sent via HTTP POST

{email: '[email protected]'}

Currently I retrieve the value of the email like so

def foo() {
    def json = request.JSON
    String email = json.email

    // remainder of action omitted          
}

If the data were being sent via URL parameters instead, I could bind it by name to an action argument like so:

def foo(String email) {

    // remainder of action omitted          
}

Is it possible to bind JSON in the request body to action arguments directly, or is this facility limited to URL and form parameters?

1 Answer 1

3

Unfortunately the binding of method/action parameters is limited to post/query string parameters and does not support obtaining them via JSON or XML.

The next best solution is to encapsulate/bind the request with a command object.

(I tested this in Grails 2.4.2).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.