Adam Bien's Weblog

JAX-RS 2.0 Client: Retrieving A List Of Instances, Problem and Solution

Retrieving a generic List in a JAX-RS 2.0 client:

List<Workshop> all = this.contextURI.request(MediaType.APPLICATION_XML).get(List.class);

Does not carry sufficient amount of information to deserialize the payload and leads to following (or similar exception):

MessageBodyReader not found for media type=application/xml, type=interface java.util.List, genericType=interface java.util.List.
	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(

The helper solves the problem by wrapping the List and providing the necessary information to the built-in deserializer (MessageBodyReader):


List<Workshop> all = target.request(MediaType.APPLICATION_XML).get(new GenericType<List<Workshop>>() {});

There is a symmetric challenge on the server counterpart sending the list to the client.

See you at Java EE Workshops at Munich Airport, Terminal 2 particularly at Effective Java EE!

NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices


A book about rethinking Java EE Patterns


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments