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.
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.
- 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
ClassCastException com.sun.org.apache.xerces.internal.dom.ElementNSImpl NullPointerException in values of element.getValue() at method public Response post(JAXBElement element)
No default no-arg constructor exception
- 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