Octavio Garbarino Octavio Garbarino - 3 months ago 8
reST (reStructuredText) Question

Grails 3 rest profile 422 Unprocessable Entity result on show action

I am having troubles with that and I am not being able to handle it and I didnĀ“t find any answer here.

I have an application in Grails 3.1.10, with rest profile, I have some Domain Classes and their respective Controllers, I can create new objects with POST to save action, update them with PUT to update action and list them with GET to index action, but I am not being able to get a proper response in a GET to show action.

I am not sure if the issue that I have is in the request or in the application

My UrlMappings is like this:

constraints {
// apply constraints here

I also tried with

get "/resources/$id"(controller:"resource", action:"show")

And same result: 422: Unprocessable Entity, "errors": [10] 0: {
"message": "Property [] of class [class ] cannot be null" "path": "/1" "_links": { "self": { "href": "http://localhost:8080/1" }- }-}
For every single property different to id.

I am doing an http get request to http://localhost:8080/resource/show/1 (or http://localhost:8080/resources/1 in the second configuration), with the followings headers: "Content-Type: application/json" and "Authorization: Bearer " (I am using spring security rest plugin to secure the application). The same request to http://localhost:8080/resource/index (or to http://localhost:8080/resources/ in the second configuration) worked perfect and returned me a json with all the objects.



I think you should check one of this two options:

  1. Use @Resource in your domain class and do nnot create a controller(grails generates it automatically in this case)

  2. If you want to have a bit more control, you can use an url mapping resource + a Controller that extends RestfulController as described in the documentation section (http://docs.grails.org/latest/guide/single.html#webServices)

In this second options you will need something like this in the URlMappings:


and also a controller like:

class BookController extends RestfulController {
  static responseFormats = ['json', 'xml']
  BookController() {