Grails currencyInstance.properties not set after currencyInstance.properties = params

84 views Asked by At

I am using Grails 2.3.3

In CurrencyController. after

currencyInstance.properties = params

currencyInstance.properties doesn't change.

But currencyInstance.properties change if I set

currencyInstance.code = params.code
currencyInstance.name = params.name

Here is my params :

println "Here is params: $params"

==> Here is params: [id:34, name:Australian dollar 1, code:AUD, version:4]

And domain

class Currency {

    String code;
    String name;

    static constraints = {
        code blank : false;
        code unique: true;
    }

    static mapping = {
    }

}
1

There are 1 answers

0
Tuan Hoang Anh On

I found error is my fail
1 - If I send http PUT to http://localhost:8080/test_parmas/api/currencies/9?name=zzzzzz and set Header Content-Type = application/json but leave empty body-data send to server.
OR
2 - If I send HTTP PUT to http://localhost:8080/test_parmas/api/currencies/9 and set Header Content-Type = application/json and body-data (have id = 9)

{
"id":9
"name":"Australian dollar 111"
}

It work if
1 - If I send http PUT to http://localhost:8080/test_parmas/api/currencies/9?name=zzzzzz
or
2 - If I send HTTP PUT to http://localhost:8080/test_parmas/api/currencies/9 and set Header Content-Type = application/json and body-data

{
"name":"Australian dollar 111"
}