Friday Jun 20, 2014

Fixed: MessageBodyReader not found for media type

I've been plagued with this error over the past few days:

Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=class com.mycompany.customerclientmaven.Customer, genericType=class com.mycompany.customerclientmaven.Customer.
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(
    at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(

This is what you get when you're running a RESTful web service client, e.g., you've created RESTful web services that expose customers, etc. Now you want to access those services. 

In your client code you have statements like this:


Everything compiles fine. Then you run the application and see the stack trace above.

Much googling later brought me to this which works out of the box:

Genson is a data-binding and streaming library for JSON. It implements the extension points MessageBodyReader and MessageBodyWriter of JAX-RS and declares its implementation with Java's service loader mechanism. That in turn allows Jersey (and other RESTful web service libraries) to automatically detect Genson and use it for JSON parsing/writing.

For Maven, it's as simple as adding this, otherwise download the JAR and add it to your classpath yourself.



Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« June 2014 »