MessageBodyProvidernotFoundFoundException在JSON WebService上使用



我有一个问题,请阅读我的WebService Client。

这是我的网络服务:

    @GET
@Path("/results")
@Produces(MediaType.APPLICATION_JSON)
public Response getPlayerResults(@QueryParam("nick") String nick, @Context HttpServletRequest request,
        @Context HttpServletResponse response) {
    // if (!isAuth(request, response)) {
    // authError(response);
    // }
    System.out.println(nick);
    GenericEntity<List<JSONTournament>> entity = new GenericEntity<List<JSONTournament>>(
            MongoTournaments.getPlayerResults(nick, null)) {
    };
    return Response.ok(entity).build();
}

我的客户端:

Client client = ClientBuilder.newClient();
        WebTarget webTarget = client.target("http://localhost:8080/WS").path("players/results");
        Response response = webTarget.queryParam("nick", nick).request(MediaType.APPLICATION_JSON).get();
        System.out.println(nick);   
        tournaments = response.readEntity(new GenericType<List<JSONTournament>>() {
        });

我得到了这个异常,而奇怪的媒体类型(text/html(而不是application/json ...:

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html;charset=utf-8, type=interface java.util.List, genericType=java.util.List<com.winascrap.database.model.JSONTournament>.
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:232)
at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:812)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:368)
at org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:122)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:419)
at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:119)

我不明白缺少或未正确完成的操作。我的对象具有@xmlrootelement注释,我使用jersey.core,jersey.media和moxy作为依赖项...(但也许我忘记了依赖项或配置?(:

感谢您的帮助!

已解决!

我错过了在用@xmlrootelement宣告的自定义类型中添加一个空构造函数。它仅能添加无参数的构造函数。

相关内容

  • 没有找到相关文章

最新更新