14

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);
Anant
  • 416
  • 1
  • 4
  • 8

1 Answers1

24

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>
Community
  • 1
  • 1
Paul Samsotha
  • 188,774
  • 31
  • 430
  • 651
  • Thanks @ppeskillet it worked. My bad should have checked the documentation. – Anant Jun 10 '15 at 11:43
  • 1
    Thanks for your answer. I was almost dead until found your answer. :) – Selim Ok Jul 20 '15 at 11:16
  • Just one remark (open to discus) . If you import the BOM instead of the dependencies separately you, you could avoid that. – Sebastien Dionne Feb 08 '16 at 00:58
  • 1
    @SebastienDionne not really. You still need to include the dependency. Bom is only good for "version control". It doesn't actually import any dependencies. The issue is that the client doesn't pull in the xml dependency, so you still need to add it – Paul Samsotha Feb 08 '16 at 01:05
  • I have `jersey-media-jaxb` in my war but I am still getting the above error. Do I need to register it? Specifically for an ArrayList (don't know if that matters). – John B Jan 12 '17 at 14:36
  • 1
    @JohnB No you shouldn't need to. You shouldn't even need to add the dependency. It should already be pulled in by Jersey server dependencies. This post is about the client (which doesn't automatically pull it in). As far as registering, it shouldn't be required. Maybe you are just missing the `@XmlRootElememt` annotation on the POJO (this is a pretty common mistake) – Paul Samsotha Jan 12 '17 at 14:38
  • @JohnB For ArrayList, it should still work. If you can't get it working, and you want to post a question with more details, I'll check it out. – Paul Samsotha Jan 12 '17 at 14:39
  • 1
    URL https://jersey.java.net/documentation/latest/migration.html#mig-2.16 is now broken (namely, it doesn't redirect to the proper page). It should be replaced with https://jersey.github.io/documentation/latest/migration.html#mig-2.16 – ErikMD Feb 01 '18 at 19:42