JsonMappingException:找不到类型的合适构造函数

时间:2013-04-08 22:27:51

标签: android google-cloud-endpoints google-eclipse-plugin

给出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项目。所有东西都会编译而没有错误等。此外,POJO ChallengeData由其他三个POJO组成,类似于:

public class ChallengeData{

  Credit credit;
  Coin  coin;
  Friend friend;

  //getters and setters
}

然后Credit和Coin只包含简单字段(即int和String),但Friend包含一些简单字段和另一个POJO。

我真的不认为JSON的深度(即POJO关系)应该重要。但我包括所有相同的细节。

1 个答案:

答案 0 :(得分:2)

您可能会收到此错误,因为您是通过端点api发送图像而忘记在Base64中对其进行编码。您必须将所有图像编码为base64字符串。这是一个link,其代码段显示了如何执行此操作。记住你是从字节编码到String。我之所以这么想是因为你提到你的服务器没有受到任何打击,但是你收到400 Bad Request错误,这意味着谷歌正在拦截你的电话并且无法解析请求。试试吧。