grails REST和POST的问题

时间:2014-05-19 03:36:36

标签: rest grails grails-2.3

我正在尝试grails 2.3.8,并使用新的REST东西......好吧,我正在尝试发布一个新的资源,非常简单......我遵循了新的文档,但我无法让它工作。

我的域名

package mobearserver
import grails.rest.*

@Resource(uri='/contracts', formats=['json', 'xml'])
class ContractInfo {

    String phoneNumber
    String companyName  
    Date dateCreated
    Date contractEndDate    
    Double balance 

    static constraints = {
    }
}

对localhost执行POST请求时:8080 / app / contracts

有了这个信息:

Content-Type: application/json

{"balance":99.89,"companyName":"Ancel","contractEndDate":"2014-05-19T03:00:00Z","phoneNumber":"9999999999"}

我一直在:

Response:
status: 422 Unprocessable Entity
Date: Mon, 19 May 2014 03:32:53 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Content-Type: application/json;charset=UTF-8

{"errors":[{"object":"mobearserver.ContractInfo","field":"balance","rejected-value":null,"message":"La propiedad [balance] de la clase [class mobearserver.ContractInfo] no puede ser nulo"},
{"object":"mobearserver.ContractInfo","field":"companyName","rejected-value":null,"message":"La propiedad [companyName] de la clase [class mobearserver.ContractInfo] no puede ser nulo"},
{"object":"mobearserver.ContractInfo","field":"contractEndDate","rejected-value":null,"message":"La propiedad [contractEndDate] de la clase [class mobearserver.ContractInfo] no puede ser nulo"},
{"object":"mobearserver.ContractInfo","field":"phoneNumber","rejected-value":null,"message":"La propiedad [phoneNumber] de la clase [class mobearserver.ContractInfo] no puede ser nulo"}]}

为什么它不识别身体?我错过了什么?

1 个答案:

答案 0 :(得分:3)

这是Grails 2.3.8的问题,如此处https://jira.grails.org/browse/GRAILS-11399所述。现在使用2.3.7或等待2.3.9,据说可以解决这个问题。