泽西FEATURE_POJO_MAPPING和错误的内容类型

时间:2017-07-10 16:34:01

标签: java jersey-client

外部服务为JSON响应返回错误的MIME类型 - text/javascript

    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    client = Client.create(clientConfig);

    WebResource webResource = client.resource(API_URL)
            .queryParam("method", "ems.get.locations");

    regions = webResource.queryParam("contentType", "region")
            .accept("text/javascript")
            .get(ClientResponse.class)
            .getEntity(EMSLocationsResponse.class).rsp.locations;

泽西岛客户无法接受:

23:26:26,745 SEVERE [com.sun.jersey.api.client.ClientResponse] (default task-48) A message body reader for Java class com.mezoline.carrier.EMSLocationsResponse, and Java type class com.mezoline.carrier.EMSLocationsResponse, and MIME media type text/javascript;charset=utf-8 was not found
23:26:26,745 SEVERE [com.sun.jersey.api.client.ClientResponse] (default task-48) The registered message body readers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.EntityHolderReader
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

是否有任何配置方式?

1 个答案:

答案 0 :(得分:0)

到目前为止

    regions = new Gson().fromJson(webResource.queryParam("type", "regions")
            .get(ClientResponse.class)
            .getEntity(String.class), EMSLocationsResponse.class).rsp.locations;