Dropwizard

时间:2016-05-07 06:13:29

标签: java rest jersey glassfish dropwizard

我已经阅读了类似的问题,但没有一个是我的问题的解决方案。所以我不认为这是重复的

我必须连接到外部服务,从中获取响应并读取给定值。首先,我做了一个带有响应表示的POJO

public class ServiceResponse {
    @JsonProperty
    public List<MyEntity> entities;
    @JsonProperty
    public Integer status;

    public ServiceResponse(List<MyEntity> entities, Integer status) {
        this.entities = entities;
        this.status = status;
    }

    //getters and setters
}

在测试中我嘲笑了通信类,所以这不是问题,响应始终存在。

现在我有一个方法,将响应映射到我的POJO类。

ServiceResponse servResponse = response.readEntity(ServiceResponse.class);

这很简单。但是,当调用此行时,我收到错误:

  

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:   找不到媒体类型= text / html,type = class的MessageBodyReader   com.mycompany.ServiceResponse,genericType = class   com.mycompany.ServiceResponse。在   org.glassfish.jersey.message.internal.ReaderInterceptorExecutor $ TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:231)     在   org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)     在   org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)     在   org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)     在   org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)     在   org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)     在   org.glassfish.jersey.client.InboundJaxrsResponse $ 1.call(InboundJaxrsResponse.java:115)     在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)     在   org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:267)     在   org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:112)

我没想到这里可能会出现问题。我宁愿打架杰克逊会引发麻烦,但不是泽西岛。如何解决这个错误?

我正在使用DW 0.9.2。

0 个答案:

没有答案