我尝试使用jackson
将http json响应转换为java对象。
webResource.accept("application/json");
ClientResponse clientResponse = webResource.path("routingRequest")
.queryParam("options", rr.options)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(ClientResponse.class);
Response routingResponse = clientResponse.getEntity(Response.class);
但是我收到了这个错误:
A message body reader for Java class com.archive.Response, and Java type class com.archive.Response, and MIME media type text/x-json was not found
和
Feb 17, 2015 12:18:34 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: A message body reader for Java class com.waze.routing.automation.dto.archive.Response, and Java type class com.waze.routing.automation.dto.archive.Response, and MIME media type text/x-json was not found
Feb 17, 2015 12:18:34 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: 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.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
如何轻松定位错过匹配问题?
更新
我甚至试图忽略尽可能多的成员:
public class RoutingResponse {
@JsonIgnore public Response response;
@JsonIgnore public Coordinate[] coords;
public Coordinate segCoords;
}
仍然无法解析JSON响应:
{
"response": {
"routeName": "המכבים, באר שבע",
"results": [{
}],
"streetNames": ["ג'ו יוסף אלון", null, "הפלמ\"ח", "המכבים", "נגבה", "דבורה", "אהוד בן גרא"],
"tileIds": [],
"displayRoute": true
},
"coords": [{
"x": 34.78103644431032,
"y": 31.243934961900017,
"z": NaN
}, {
"x": 34.779020165815155,
"y": 31.242382384889336,
"z": NaN
}],
"segCoords": null
}
答案 0 :(得分:0)
原因是响应的媒体类型:text / x-json 它必须是" application / json"被你的图书馆接受。