Jersey客户端抛出MessageBodyProviderNotFoundException

Jersey客户端抛出MessageBodyProviderNotFoundException,jersey,jax-rs,moxy,Jersey,Jax Rs,Moxy,我有一个Jersey客户端,它抛出MessageBodyProviderNotFoundException 在我的示例中,我可以使用moxy解析从文件读取的JSON,然后尝试使用Jersey客户端解析相同的JSON 我检查了moxy解析创建的WarehouseResponse实例,它看起来很完美 我的依赖关系 <dependencies> <dependency> <groupId>org.glassfish.jersey.core

我有一个Jersey客户端,它抛出MessageBodyProviderNotFoundException 在我的示例中,我可以使用moxy解析从文件读取的JSON,然后尝试使用Jersey客户端解析相同的JSON

我检查了moxy解析创建的WarehouseResponse实例,它看起来很完美

我的依赖关系

  <dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.27</version>
    </dependency>
    <dependency>
        <groupId>com.ca.Plex</groupId>
        <artifactId>ObRun</artifactId>
        <version>7.2.1.002</version>
        <scope>system</scope>
        <systemPath>C:/ProgramData/CA/Plex/7.2.1/ObJava/lib/ObRun.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.27</version>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.1.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>2.27</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <version>2.27</version>
    </dependency>
  </dependencies>

服务器正在将内容类型设置为text/x-json。 我在得到响应后设置响应头

public static WarehousesResponse executeGET(ObCharFld obUri, ObCharFld obPath) {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(obUri.getValue())
            .path(obPath.getValue());
    Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
    Response response = builder.get();
    response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    return  response.readEntity(WarehousesResponse.class); 
}

你能发布完整的堆栈跟踪吗?堆栈跟踪添加到post中是因为某种原因,服务器发送的内容类型为
text/x-json
。Jersey可能不知道这与
application/json
有什么相同之处。在阅读之前,您可以尝试使用
application/json
。“看看会发生什么。”保罗·萨姆索塔,这很有效。我没有编写服务器,也没有可用的源代码,因此可能是这样
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/x-json;charset=UTF-8, type=class com.pacorini.rest.client.WarehousesResponse, genericType=class com.pacorini.rest.client.WarehousesResponse.
    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:1091)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
    at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:321)
    at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:115)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:229)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
    at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
    at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:112)
    at com.pacorini.rest.client.PlexExample.executeGET(PlexExample.java:41)
    at com.pacorini.rest.client.PlexExample.main(PlexExample.java:32)
public static WarehousesResponse executeGET(ObCharFld obUri, ObCharFld obPath) {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(obUri.getValue())
            .path(obPath.getValue());
    Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);
    Response response = builder.get();
    response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    return  response.readEntity(WarehousesResponse.class); 
}