Jersey Integration Challenges

0

Jersey is suppose to make things easier. Well, it does, but also add’s its own set of challenges along the way. A bunch of crazy exceptions that our developer community out there is completely unclear on how to solve. So with this blog, I hope to document some common causes and fixes for most of the exceptions that I have got.

Exception 1
SEVERE: A message body writer for Java class package.java, and Java type class package.java, and MIME media type application/octet-stream was not found.
Causes

  • You have missed the @XmlRootElement annotation in the java class
  • Ensure that your @XmlRootElement is on both server and client side, this is easy to forget, be careful here.
  • Ensure that you copy your jar to WEB-INF/lib folder
  • Make sure that you have jersey json jar file included in your classpath
  • Sounds silly, but Refresh your jersey project for new jar’s added with the above fixes

Exception 2
ClassCastException com.sun.org.apache.xerces.internal.dom.ElementNSImpl NullPointerException in values of element.getValue() at method public Response post(JAXBElement element)
OR
No default no-arg constructor exception
Causes

  • I can bet you forgot to add a “no-arg default constructor”
  • forgot some setters and getters. Trust me, watch this carefully, infact use the Eclipse->RightClick->Source->Getters and Setters