给定 api 端点
@ApiMethod(name = "sendChallenge", httpMethod = HttpMethod.POST)
public ExchangeList sendChallenge(ChallengeData request) throws Exception {
return getFromDBThenProcess(request);
}
前端(android)调用端点
ExchangeList transfers = service.sendChallenge(request).execute();
我从 LogCat 获得以下堆栈跟踪。
注意:我正在监视我的服务器控制台 (localhost),但没有来电。
堆栈跟踪:
04-08 14:58:53.261: D/dalvikvm(940): GC_CONCURRENT freed 1394K, 15% free 12495K/14599K, paused 15ms+15ms, total 75ms
… //[many of those `freed` lines]
04-08 14:58:54.742: D/dalvikvm(940): GC_CONCURRENT freed 1394K, 15% free 12506K/14599K, paused 15ms+16ms, total 85ms
04-08 14:58:55.562: W/System.err(940): com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
04-08 14:58:55.562: W/System.err(940): {
04-08 14:58:55.562: W/System.err(940): "code": 0,
04-08 14:58:55.562: W/System.err(940): "message": "com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.myapi.games.message.ChallengeData]: can not instantiate from JSON object (need to add/enable type information?)\n at [Source: N/A; line: -1, column: -1]"
04-08 14:58:55.572: W/System.err(940): }
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:314)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1060)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
04-08 14:58:55.572: W/System.err(940): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
04-08 14:58:55.572: W/System.err(940): at com.myapi.games.utils.sendChallenge.doInBackground(sendChallenge.java:70)
04-08 14:58:55.582: W/System.err(940): at com.myapi.games.utils.sendChallenge.doInBackground(sendChallenge.java:1)
04-08 14:58:55.582: W/System.err(940): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 14:58:55.582: W/System.err(940): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-08 14:58:55.582: W/System.err(940): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-08 14:58:55.582: W/System.err(940): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-08 14:58:55.592: W/System.err(940): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-08 14:58:55.592: W/System.err(940): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-08 14:58:55.592: W/System.err(940): at java.lang.Thread.run(Thread.java:856)
这是关于一个 appengine 连接的 android 项目。一切都编译没有错误,等等。 POJOChallengeData
由其他三个 POJO 组成,类似于:
public class ChallengeData{
Credit credit;
Coin coin;
Friend friend;
//getters and setters
}
那么 Credit 和 Coin 都只包含简单的字段(即 int 和 String),但 Friend 包含一些简单的字段和进一步的 POJO。
我真的认为 JSON 的深度(即 POJO 关系)并不重要。但我包括所有相同的细节。