Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:15:23+00:00 2026-06-04T20:15:23+00:00

Question : is there a way to do automatic command object binding with request.JSON

  • 0

Question: is there a way to do automatic command object binding with request.JSON data?

Given this simple Command object in my grails controller:

class ProfileCommand{

int id
String companyName

static constraints = {
    companyName blank: false
    id nullable: false
}

@Override
public String toString() {
    return "ProfileCommand{id=$id, companyName='$companyName'}";
}
}

and my controller method signature of:

def update(ProfileCommand command) {...}

How can I get request.JSON data into my command object?

So far, the only way I’ve been able to do it is to create the command object manually within the update() method, passing in request.JSON as the constructor argument:

    def command = new ProfileCommand(request.JSON)

    log.debug "Command object contents: $command"

The above debug command produces:

Command object contents: ProfileCommand{id=1, companyName='Blub Muckers'}

Which is exactly what I want (A big shout-out to Oliver Tynes for the above solution). Unfortunately, calling command.validate() after I create the command produces the following exception:

Class org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
Message Tag [validate] is missing required attribute [form]

I’m using v2.0.3, uris produced the same exception w/ v2.0.4.

UPDATE
Per Ian Roberts on the grails mailing list, you need to add the @Validateable annotation to the command class to get validate() to work. Thanks, Ian!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:15:24+00:00Added an answer on June 4, 2026 at 8:15 pm

    I’m not sure if there is anything configuration-wise to do automatic JSON parameter data binding; one thing you might be able to do is to write a Filter for your actions that take JSON request input that basically remaps request.JSON directly onto the root params map, which should in theory allow the automatic data binding to take place.

    something like:

    class JSONParamMapFilters {
      def filters = {
         before = {
            remapFilter(controller:'yourController', action:'update') {
               request.JSON.each { k,v ->
                   params[k] = v
               }
            }
         }
      }
    }
    

    You could then extend this filter via regex/naming conventions to any applicable controller actions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is simple: is there a way to totally automate the process to
Question: Is there a way to check if a given font is one of
Simple question here: is there any way to convert from a jagged array to
Sorry for this horrid, horrid question.. but there's no way for me to not
Question: Is there a way to load a lein plugin, say codex or lein-beanstalk,
Question Is there a way to define a method only once in C# (in
Silly question - Is there a way to download the iPhone SDK without Xcode
there's a question: Is there any way to pair Bluetooth device in Windows programmatically?
Possible duplicate question: Is there a way to indefinitely pause a thread? In my
The real question: Is there a way to clear certain attributes for all components

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.