I have wrote a JAX-RS server and client both use Jersey. I want to sent a collection of my entities to client and I made this steps:
This very same exception is also thrown by jersey-media-moxy for silly mistakes like using an @XmlAttribute
annotation where you really need an @XmlElement
. This was the case in my scenario, and this is something to look into especially if the problem only happens for certain classes but others work fine.
For Gradle, add the following dependency:
compile group: 'org.glassfish.jersey.media',
name : 'jersey-media-moxy',
version : '2.24.1'
Your entity class does not have an empty constructor, which is needed for the JAX-RS unmarshalling.
Have a look here:
https://blogs.oracle.com/groundside/entry/jax_rs_2_0_messagebodyreader
Sorry to resurrect this post, but I was having this problem with a Maven project and found that I needed to include a dependency for jackson-jaxrs-json-provider
in my pom:
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.4.1</version>
</dependency>
MVN Repository: http://mvnrepository.com/artifact/com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider
Adding this dependency has fixed my error while other suggested answers did not:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>${jersey2.version}</version>
</dependency>
Could it be that you have dependencies to:
jersey-common-2.25.1.jar
jersey-media-json-jackson-2.25.1.jar
...?
I had that in a rich java application that performs client rest calls. When I assembled the executable jar for this client all dependencies gets unpacked into one jar file. It turned out that both these files got a file org.glassfish.jersey.internal.spi.AutoDiscoverable ...WITH DIFFERENT CONTENT!
Everything woked fine in my IDE, bit once assembled in one jar the content that was needed was overwiritten by the other one.
The solution turned out to be how the order, and with a couple of exclusions, in the dependencies was declared. I put this early in the list:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
Later down I put:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.25.1</version>
</dependency>
I also excluded any other dependencies to jersey-common from other dependencies. Best regards Fredrik