I am using restful service in grails. I have 2 classes Person
import grails.rest.Resource
@Resource(formats=['json', 'xml'])
class Person {
String name
Address address
static constraints = {
}
}
and Address
as
import grails.rest.Resource
@Resource(formats=['json', 'xml'])
class Address {
String house
static constraints = {
}
}
and in bootstrap I could create new person entry as follows
new Person(name:"John" , address: new Address(house:"John Villa").save()).save();
but the problem is I want to do the same thing using a POST request with JSON data. I set the UrlMappings.Groovy like
"/app/person"(resources: "person", includes: ['index', 'show', 'save', 'update', 'delete', 'create', 'patch'])
"/app/address"(resources: "address", includes: ['index', 'show', 'save', 'update', 'delete', 'create', 'patch'])
then I tried using POSTMAN rest client by sending a POST request to '/app/person' with JSON data
{
"name":"john" ,
"address": "{'house' :'sample address' }"
}
but it gives error 422 unprocessable entity.
How can I do the same using JSON ? I want to do both insertion and updation using POST and PUT methods.