我想JAXRS閱讀的文本/ XML響應MessageBodyProviderNotFoundException
Client client = ClientBuilder.newClient();
String seLogerAPI = "http://ws.seloger.com/search.xml";
// Defining some query params. Full doc : https://github.com/bodinsamuel/seloger-php/blob/master/API.md
// More : https://github.com/pasnox/housing/blob/master/SeLoger.com.api.txt
WebTarget target = client.target(seLogerAPI)
.queryParam("idtypebien", "1") // apartements
.queryParam("idtt", "1") // Renting
.queryParam("nb_pieces", "5")
.queryParam("cp", "95330")
;
Response result = target.request(MediaType.TEXT_XML_TYPE).get();
ResponseRecherche res = result.readEntity(new GenericType<ResponseRecherche>() {});
System.out.println(res);
消耗Web服務返回的XML數據。但是我面對這個錯誤:化MessageBodyReader找不到媒體類型=文本/ XML的,字符集= UTF- 8
Response result = target.request(MediaType.TEXT_XML_TYPE).get();
工作正常,但是當我試圖把它的POJO使用
ResponseRecherche res = result.readEntity(new GenericType<ResponseRecherche>() {});
提出org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException ...
參考:ResponseRecherche是一個POJO,它的結構與web服務的結果相同。我下面這個教程:https://vaadin.com/blog/-/blogs/consuming-rest-services-from-java-applications
我真的不明白爲什麼
我的pom.xml
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>2.25</version>
</dependency>
感謝您閱讀
解決,我的POJO的確,我錯過了XmlRootElement將註釋!謝啦 ! – YukiAsuna