I’m trying to get a simple object to JSON format from my Jetty server using Jersey.
I keep getting the error:
SEVERE: A message body writer for Java class my.package.resources.Album, and Java type class my.package.resources.Album, and MIME media type application/json was not found
One problem is that I’m not sure where to put the POJOMappingFeature with Jetty, I have tried the following but neither changes the error:
myServletHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
and
myServletContextHandler.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
I know the basic REST functionality of Jersey is working because before I tried the JSON output I used plain text and it worked great.
I was super disappointed when I saw this one not answered as I’ve been fighting it all day. Finally figured it out so here’s what worked for me.
What I was doing:
What I needed to do:
I had to make sure to specify my Jersey packages and my POJOMappingFeature flag as init params. Hope this helps.