I'm trying to create a very simple example rest service that produces JSON. My understanding is that Jersey should auto discover the Jackson libraries (if they're on the classpath) and the JSON marshalling should happen automatically.
The following error is reported when I call GET. Am I using the appropriate dependencies for this to work or am I missing something more fundamental?
SEVERE: MessageBodyWriter not found for media type=application/json, type=class jsonex.Person, genericType=class jsonex.Person.
Dependencies
I'm using Gradle with the gretty plugin applied and these dependencies:
dependencies {
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2+'
runtime group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: '2.23'
runtime group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.7'
}
Application class
package jsonex;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Collections;
import java.util.Set;
@ApplicationPath ("services")
public class PersonApp extends Application {
@Override
public Set<Object> getSingletons() {
return Collections.singleton(new PersonService());
}
}
Service class
package jsonex;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("people")
public class PersonService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Person getPerson() {
Person me = new Person();
me.setFirstName("Dave");
me.setLastName("R");
return me;
}
}
POJO
package jsonex;
public class Person {
String firstName, lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Thanks!