Dan Nixon
Dan Nixon

Reputation: 101

Why is Cloud Endpoints throwing com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException while mapping POJOs in a List?

I'm receiving this error:

com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token↵ at [Source: N/A; line: -1, column: -1] (through reference chain: com.test.web.TestFM["fields"])

I've mocked up a simplified version of my situation that throws the same error:

Cloud Endpoint:

@Api(name = "testApi", version = "v1", clientIds={Constants.WEB_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID})
public class TestEndpoint {
    public void Test(TestFM test){
        // nothing necessary here to recreate
    }
}

TestFM:

public class TestFM {
    public int id;
    public List<SubTestFM> fields;
}

SubTestFM:

public class SubTestFM {
    public String property1;
    public String property2;
}

Javascript:

gapi.client.testApi.testEndpoint.test({
    id:7, 
    fields:[
        { property1: 'test', property2: 'test2' }, 
        { property1: 'test3', property2: 'test4' }
    ]
}).execute(function(resp){console.log(resp);});

I had thought this might be a limitation of endpoints until I realized that when submitting the same data through the API Explorer, everything works exactly as expected.

The successful Request produced by API Explorer:

POST http://localhost:8888/_ah/api/testApi/v1/Test

Content-Type:  application/json
X-JavaScript-User-Agent:  Google APIs Explorer

{
 "id": 7,
 "fields": [
  {
   "property1": "test",
   "property2": "test2"
  },
  {
   "property1": "test3",
   "property2": "test4"
  }
 ]
}

Any help is greatly appreciated!

Upvotes: 1

Views: 401

Answers (1)

Dan Nixon
Dan Nixon

Reputation: 101

After reading my question, I realized there was a reasonable probability that the field name "fields" is reserved or otherwise used by one of the libraries involved in Google Cloud Endpoints.

Changing the name from "fields" (in TestFM above) has resolved this error in the test code above and in my own code.

Upvotes: 1

Related Questions