DropWizard无法序列化JSON

时间:2016-02-10 02:25:01

标签: java json jackson dropwizard

即便是这样的消息也会失败:

{
    "message": "Hi!"
}

出现此服务器端错误:

! java.lang.IllegalStateException: Committed
! at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1243) ~[test-jar.jar:na]
! at org.eclipse.jetty.server.Response.sendError(Response.java:567) ~[test-jar.jar:na]
! at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:484) ~[test-jar.jar:na]
! at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) ~[test-jar.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) ~[test-jar.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) ~[test-jar.jar:na]
! at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) ~[test-jar.jar:na]
! at io.dropwizard.jetty.NonblockingServletHolder.handle(NonblockingServletHolder.java:49) ~[test-jar.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669) ~[test-jar.jar:na]
! at io.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:29) ~[test-jar.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[test-jar.jar:na]
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.handle(AllowedMethodsFilter.java:43) ~[test-jar.jar:na]
! at io.dropwizard.jersey.filter.AllowedMethodsFilter.doFilter(AllowedMethodsFilter.java:38) ~[test-jar.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[test-jar.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [test-jar.jar:na]
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [test-jar.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [test-jar.jar:na]
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [test-jar.jar:na]
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [test-jar.jar:na]
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [test-jar.jar:na]

这是失败的方法:

@GET
@Path("/test/{id}")
public Response test(@PathParam("id")
                                  String id, @QueryParam("alt")
                                  String alternativeSerializationFormat) {
    Response getEntityResponse;

    String message  = "{\"message:\": \"Hi!!!\"}";
    getEntityResponse = Response.ok().entity(message).type(MediaType.APPLICATION_JSON_TYPE)
            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_TYPE+"; charset=UTF-8").build();
    return getEntityResponse;
}

我认为这可能是类路径问题。有没有人对可能导致这种情况的原因有什么建议?我们使用Avro迫使我们在我们的类路径和杰克逊2上拥有杰克逊1。

0 个答案:

没有答案