JaxRS read text/xml response MessageBodyProviderNotFoundException

Viewed 1868

I want to consume a webservice returning XML data by

    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);

However i'm facing this error : MessageBodyReader not found for media type=text/xml;charset=utf-8

Response result = target.request(MediaType.TEXT_XML_TYPE).get(); 

is working fine but when i try to put it in POJO by using

ResponseRecherche res = result.readEntity(new GenericType<ResponseRecherche>() {});

the org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException is raised...

FYI : ResponseRecherche is a POJO that has the same structure than the answer from the webservice. I was following this tutorial : https://vaadin.com/blog/-/blogs/consuming-rest-services-from-java-applications

I don't really understand why

My 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>

Thanks for reading

1 Answers
Related