I'm using jersey-client:2.28, jersey-hk2:2.28 and jersey-media-jaxb:2.28 maven targets to create a client that will consume a RESTful service. All beans have XmlRootElement annotations and default empty constructors. Yet when calling the service like this:
JAXBElement<XYZ> post = target.request( MediaType.APPLICATION_XML ).post( Entity.entity( xzyRequest, MediaType.APPLICATION_XML ), JAXBElement.class );
I get:
javax.ws.rs.client.ResponseProcessingException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/xml, type=class javax.xml.bind.JAXBElement, genericType=class javax.xml.bind.JAXBElement
I know the jersey-media-jaxb provider is being discovered, because it is being used to write the message body when initiating the request. I know the response has valid xml as I'm able to parse it like so:
String responseString = target.request( MediaType.APPLICATION_XML )
.post( Entity.entity( xyzRequest, MediaType.APPLICATION_XML ), String.class );
Unmarshaller unmarshaller= JAXBContext.newInstance( XYZ.class ).createUnmarshaller();
XYZ zyx = ( ( JAXBElement<XYZ> ) unmarshaller.unmarshal( new StringReader( xmlResponse ) ) ).getValue();
I don't particularly mind parsing the XML, but I'd like to know why Jersey is unable to do so.