0

I have a grails controller making a REST call using HTTPBuilder to a Spring backend:

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
}

Everything is fine, except when getting the JSON response, there is this new property called "new." Here is the Settings object about to be returned as JSON from my Spring backend:

Object about to be returned as JSON

And here it is as the JSON response in the grails controller. Notice the extra fifth property that is not part of the original Settings object.:

After getting the response

Does anyone have an idea how this mysterious property called "new" keeps getting added on?

jcd
  • 221
  • 4
  • 15
  • if you say a new property, since when? any changes made recently you can pinpoint this or got it noticed just now? – cfrick Mar 04 '15 at 18:24
  • I just noticed it, actually. By new, I mean the name of the property is "new". (The second image has it). I'm not actually when this started occurring, but I noticed it does it for every one of our domain objects when passed back from spring. – jcd Mar 05 '15 at 00:03
  • what propertie shas "result" variable just before "render result as JSON" call? What class is it? – practical programmer Mar 05 '15 at 07:21

1 Answers1

0

After running into the spring-data jpa docs here,

I see that spring data will add a property "new" based on if the id column is null or not null. The following is taken directly from the docs:

"Id-Property inspection (default) By default Spring Data JPA inspects the Id-Property of the given Entity. If the Id-Property is null, then the entity will be assumed as new, otherwise as not new."

jcd
  • 221
  • 4
  • 15