Google Http Client Library java:com.fasterxml.jackson.core.JsonParseException:意外字符('G'

时间:2014-11-07 11:01:41

标签: java json google-http-client

我正在制作一个HTTP get请求,它给了我一个JSON响应:

{ time : 1345111524000
  sub : Test vote
  msg :
  remain : 420
  cur_time : 1345113672856
  ver : 1.2.2
  p_type : 0
  .....

我正在使用Google HTTP Client Library for Java

我的实施

static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
static final JsonFactory JSON_FACTORY = new JacksonFactory();

public static class PollInfo{
    @Key("time")
    public String time;

    @Key("sub")
    public String sub;

    @Key("msg")
    public String msg;

    .
    .
    }

    public static class PollInfoUrl extends GenericUrl{
       public PollInfoUrl(String encodedUrl) {
         super(encodedUrl);
       }
    }

    public PollInfo getPollInfo()  throws Exception{
     HttpRequestFactory requestFactory =HTTP_TRANSPORT.createRequestFactory(
                     new         HttpRequestInitializer() {
          @Override
          public void initialize(HttpRequest request) {
            request.setParser(new JsonObjectParser(JSON_FACTORY));
          }
    });
     PollInfoUrl url = new PollInfoUrl("http://**IP**:8000/web1/num1?cmd=en_poll_info&src=src_web&ver=default&deviceToken=DUMMYDEVICETOKEN&ref_id=83f2491d-0b0c-4d1c-8a14-053256cf157a&p_type=0&p_creator=Wp&eid=3&sender=Wp";);
     HttpRequest request = requestFactory.buildGetRequest(url);
     PollInfo pollInfo = request.execute().parseAs(PollInfo.class);
     return pollInfo;
}//getPollInfo();

我能够在我的项目中解析其他URL但是对于这个特殊情况,它给了我例外,我需要一些指导来解决它。 以下是我的服务器异常日志

[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.fasterxml.jackson.core.JsonParseException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.fasterxml.jackson.core.JsonParseException: Unexpected character ('Q' (code 81)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@481a98fe; line: 1, column: 2]
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:667)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:587)
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:605)
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:393)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
    at hello.common.ui.gwt.server.GWTCacheControlFilter.doFilter(GWTCacheControlFilter.java:50)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

请指导我哪里出错了。 :)提前谢谢。

1 个答案:

答案 0 :(得分:0)

您收到的JSON似乎无效。它缺少引号和逗号。