I got the following error message every time I try to call my REST service
[2016-09-01T16:27:37.782+0200] [Payara 4.1] [SEVERE] [] [org.glassfish.jersey.message.internal.WriterInterceptorExecutor] [tid: _ThreadID=28 _ThreadName=http-listener-1(3)] [timeMillis: 1472740057782] [levelValue: 1000] [[MessageBodyWriter not found for media type=application/json, type=class xxx.JsonClass, genericType=class xxx.JsonClass.]]
Here's the REST service (stripped to the relevant part):
import javax.ejb.EJB;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("/service")
public class Service {
@GET
@Path("/callme")
@Produces(MediaType.APPLICATION_JSON)
public JsonClass callme(//
@QueryParam("test") final String test, //
....) {
return new JsonClass();
}
}
The JSON Class
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
public class JsonClass {
private String test;
public JsonClass(final String test....) {
...
}
@JsonProperty
public String getTest() {
return this.test;
}
}
POM.xml (interesting parts)
<!-- DO NOT change the scope for jersey: https://java.net/jira/browse/JERSEY-1941 -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.8</version>
<scope>provided</scope>
</dependency>
My setup is:
- JDK8/JEE7 (build 1.8.0_51-b16)
- Glassfish 4.1 Payara
- Maven 3.2.5
This is what I tried so far:
- MessageBodyWriter not found for media type=application/json -> Doesn't work because I run into a problem with Glassfish 4 and Weld (https://java.net/jira/browse/JERSEY-1941)
- SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.jersey.jaxb.Todo, genericType=class com.jersey.jaxb.Todo -> As seen in the POM.xml above it's already included and does not work
- https://java.net/jira/browse/JERSEY-2715 -> Annotation @Produces is already there and doesn't help either
- Obtaining "MessageBodyWriter not found for media type=application/json" trying to send JSON object through JAX-RS web service - GENSON with @XmlAttribute had not the desired effect
- I tried to keep the JSON object as simple as possible to avoid problems with arrays and complex objects -> No change
I still think it's a dependency problem here. However I'm out of ideas what could be the problem.