Grails null service in controller




















Already on GitHub? Sign in to your account. My intention is to construct an object graph from the JSON object, and then call the. In a normal Grails application, you do not have to specify an Id for an object in a relationship, and it gets persisted and populated with an Id when persisted.

The text was updated successfully, but these errors were encountered:. Does the same thing happen if you eliminate "id": null from the ruta object map in your JSON? Sorry, something went wrong. The same thing happens. The Id must exist and its value must not be null for it to work if the object is embedded. Proof of this is that the main object that contains the embedded "ruta" has a null Id and it manages to reach the REST endpoint. One question: the main object that contains "ruta" which means route in English used to have a many-to-one relationship with the main object that contains it which is the cattleman.

The idea that I had in my head is that a route belonged to the cattleman, and that the relationship had to be that many cattleman could be located in one route.

That meant putting a Route object in my cattleman domain, and a cattleman in my Route domain with a [belongsTo] to have a bidirectional relationship plus cascade saves and possibly deletes. Do you think that may had something to do with it? Although, I can not see how that could possibly cause the route to be a null object in my REST endpoint.

Something else must be causing a deserialization problem when there are embedded objects in a JSON object. In the end I had to settle for a one-to-many relationship between Routes and Cattlemen, as that made the most sense, and save the route first, so that it could have an id, so that I could later send a request to my endpoint with an embedded Route with just one property the Id of the route , so that I could persist the whole object graph.

Despite this, it would be sweet if could construct the whole graph first, and then make it persist by sending it to my rest endpoint, following, of course, the rules of cascades saves and deletes. For now I would just like to know why the route is arriving as a null route unless I give it a non-null Id even if said Id doesn't even exist in the database yet. I ran your test project and, indeed, the route reaches the rest endpoint but, only as long as I don't have a null Id property in the route.

This one's route reaches the endpoint just fine and I get back as a response the description of the route, as you coded it. Now, in this one:. I can't recreate that and it doesn't make sense that the payload would affect whether or not the endpoint is reached. The payload isn't even interrogated until after the endpoint has been identified.

Then you call: this. Bruno Vieira 3, 1 1 gold badge 22 22 silver badges 35 35 bronze badges. Original link seems to be dead. Here's the updated link to 2. Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 0. Related 2. Hot Network Questions. The object will not be persisted immediately unless the flush argument is used:. The save method returns null if validation failed and the instance was not persisted, or the instance itself if successful.

This lets you use "Groovy truth" null is considered false to write code like the following:. ValidationException if validation fails.

This behavior may also be triggered by setting the grails. If the Config property is set and the argument is passed to the method, the method argument will always take precedence. This is true by default - set to false to disable cascading validation. Table of contents 1 Introduction. Quick Reference Improve this doc.



0コメント

  • 1000 / 1000