j.Stark j.Stark - 17 days ago 8
JSON Question

Error while generating json content using jersy

I'm working on jersy project when a lunch tomcat server i get this exception :

MessageBodyWriter not found for media type=application/json

This is my code :

@Path("/activities")
public class ActivityResource {

private ActivityRepository activityRepository = new ActivityRepositoryStub();


@GET
@Produces(MediaType.APPLICATION_XML)
public List<Activity> getAllActivities(){

return activityRepository.findAllActivities();


}

Answer

You need to add jersy-media-moxy jar in your Lib folder or add it in your pom.xml that why you have this error message

if you want to return xml content make shur that you have @XmlRootElement on your entity because jersy use JAXB to map java object to xml

@XmlRootElment
public class Activity {



}