REST调用后使用HTTPBuilder和Grails出现奇怪的“新”属性

时间:2015-03-04 17:39:57

标签: json spring rest grails httpbuilder

我有一个grails控制器使用HTTPBuilder对Spring后端进行REST调用:

def getSettings(String customerID) {
    def http = new HTTPBuilder( grailsApplication.config.com.company.product.productWebserviceURL )
    def result = [:]
    def postBody = [customerID: customerID]

    try {
        http.post(path: 'product/getSettings', body: postBody, requestContentType: URLENC) { resp, json ->
            result = json
        }
    } catch (IOException ex) {
        logger.error("Cannot in attempting to get settings via webservice for customerID: " + customerID + ". Is the server running? \nError: " + ex.getMessage())
        result['errors'] = [[message : this.CUSTOMER_FACING_TRANSACTIONHISTORY_DOWN_MESSAGE]]
        response.status = 500;
    }
    render result as JSON
}

一切都很好,除了获得JSON响应之外,还有一个名为" new的新属性。"以下是我的Spring后端将作为JSON返回的Settings对象:

Object about to be returned as JSON

这里它是grails控制器中的JSON响应。请注意不属于原始Settings对象的额外第五个属性。:

After getting the response

有没有人知道这个神秘的财产如何称为" new"不断加入?

1 个答案:

答案 0 :(得分:0)

进入spring-data jpa docs here,

之后

我看到spring数据会添加一个属性" new"基于id列是否为null或不为null。以下内容直接来自文档:

" Id-Property检查(默认)默认情况下,Spring Data JPA会检查给定实体的Id-Property。如果Id-Property为null,则该实体将被假定为new,否则为新的。"