Reputation: 311
I implemented a Jersey service using embedded Jetty + Jackson. Though when I try it with a GET resource (that does not consume nor produce JSON) it works, it does NOT with the POST resource. The message on the console reads:
SEVERE: MessageBodyReader not found for media type=application/json, type=class com.delta.model.EnableDisableMessage, genericType=class com.delta.model.EnableDisableMessage
The POST resource:
@POST
@Path("/enable")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String enablePost(EnableDisableMessage enable) throws InterruptedException {
logger.debug("within Proxy POST method..." + enable.toString());
return "it worked!";
}
The model:
package com.delta.model;
public class EnableDisableMessage {
private String cell;
private String instruction;
public EnableDisableMessage(String cell, String instruction) {
super();
this.cell = cell;
this.instruction = instruction;
}
public String getCell() {
return cell;
}
public void setCell(String cell) {
this.cell = cell;
}
public String getInstruction() {
return instruction;
}
public void setInstruction(String instruction) {
this.instruction = instruction;
}
}
I also implemented this configuration class as detailed by Jersey specs:
@ApplicationPath("/")
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("com.delta.model;com.delta.rest");
register(JacksonFeature.class);
// property(CommonProperties.MOXY_JSON_FEATURE_DISABLE, true);
}
}
pom.xml's dependencies:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.3.v20140905</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.2.3.v20140905</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>2.7</version>
</dependency>
<!--
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.7</version>
</dependency>
-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
Upvotes: 1
Views: 3421
Reputation: 1982
Maybe including the Jackson JSON-provider in your dependencies does help?
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.1</version>
</dependency>
Upvotes: 3