我有一個REST服務和客戶端。我試圖調用此服務直接使用JSON並將其轉換爲我需要的對象。但它不起作用。我收到以下錯誤:未找到用於Java類com.a.b.c.D和Java類型類com.a.b.c.D和MIME媒體類型application/json的消息正文閱讀器。澤西REST服務不消費JSON
服務:
@Path("/getListPrice")
public class ListPriceService {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Type(PricingObject.class)
public Response search(PricingObject pricingObject, @Context final HttpHeaders headers) {
.........
return Response.ok().entity(pricingObject).build();
}
}
客戶:
WebResource webResource = client.resource(url);
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON_TYPE)
.post(ClientResponse.class, pricingObjectRequest);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
誰能告訴我是什麼問題呢?
我已經將您提到的更改添加到了我的web.xml以及我的客戶端,但仍然遇到同樣的問題。 –
這是服務器端問題嗎?這是你在哪裏得到例外?如果是的話,表明你的web.xml –
我想通這個問題,沒有正確添加在init-PARAM和也不得不添加此 \t \t \tcom.sun.jersey.config.property.resourceConfigClass \t \t \t com.sun.jersey.api.core。PackagesResourceConfig param-value> \t \t –