JAX-RS / Jersey how to customize error handling?

I’m learning JAX-RS (aka, JSR-311) using Jersey. I’ve successfuly created a Root Resource and am playing around with parameters: @Path(“/hello”) public class HelloWorldResource { @GET @Produces(“text/html”) public String get( @QueryParam(“name”) String name, @QueryParam(“birthDate”) Date birthDate) { // Return a greeting with the name and age } } This works great, and handles any format in … Read more

What’s the difference between text/xml vs application/xml for webservice response

This is more of a general question about the difference between text/xml and application/xml. I am fairly new to writing webservices (REST – Jersey). I have been producing application/xml since it is what shows up in most tutorials / code examples that I have been using to learn, but I recently found out about text/xml … Read more

A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found

I am trying to get a web service to work which returns a JSON (JAX-RS with jersey implementation on Tomcat). However, I am getting the below exception. I have looked at the similar problems here, but none of the solutions work for me, and it’s been more than half a day 🙁 07-Nov-2017 20:47:17.109 SEVERE … Read more

org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException

The problem: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer indicates that you try to use the Jersey 2.x servlet, but you are supplying the Jersey 1.x libs. For Jersey 1.x you have to do it like this: <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>sample.hello.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> For more information check the Jersey 1.x documentation. If you instead … Read more