![](/img/trans.png)
[英]com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException while implementing One-To-Many bidirectional relationship App Engine
[英]Why is Cloud Endpoints throwing com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException while mapping POJOs in a List?
我收到此錯誤:
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"])
我模擬了我的情況的簡化版本,並拋出了相同的錯誤:
雲端點:
@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);});
我一直以為這可能是端點的限制,直到我意識到通過API資源管理器提交相同的數據時,一切都會按預期運行。
API資源管理器成功生成的請求:
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"
}
]
}
任何幫助是極大的贊賞!
讀完我的問題后,我意識到Google Cloud Endpoints所涉及的庫之一保留或以其他方式使用了字段名“ fields”。
從“字段”(在上面的TestFM中)更改名稱已解決了上面的測試代碼和我自己的代碼中的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.