Jersey version issue: MessageBodyReader not found for media type=application/xml

Anant picture Anant · Jun 10, 2015 · Viewed 15.3k times · Source

While writing a simple Jersey client that was consuming XML data, I came across this exception "MessageBodyReader not found for media type=application/xml". All of my settings, including the jersey-client as maven dependencies was just fine. The version that I was using was 2.17. Once I degraded the version to 2.15 it started working fine. Can anyone explain what dependencies that needs to be included for version 2.17 to work.

Maven Dependency (works on 2.15 and lower)

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey.version}</version>
</dependency>

Java Code Snippet for consuming the service

Client c = ClientBuilder.newClient();
WebTarget target = null;
target = c.target(Main.BASE_URI_XML);

String customerId = "415D7AB5";

XYZ response = target.path(customerId).request(MediaType.APPLICATION_XML).get(XYZ.class);

Answer

Paul Samsotha picture Paul Samsotha · Jun 10, 2015

Have a look at 27.3. Migrating from Jersey 2.15 to 2.16

27.3.1.1. JAX-B providers separated from the core

From version 2.16 onwards, all JAX-B providers are being bundled in a separate module.

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-jaxb</artifactId>
    <version>2.17</version>
</dependency>