Skip to content
Advertisement

JAX-RS MessageBodyReader

I’m learning how the MessageBodyReader method works from the providers. I see the method returns an object and I’m not sure how to access the object from a service. Could I get an explanation on how to get the object returned from the reader class? This would help me apply a reading rule for all DTOs. Thanks in advance!

Service:

JavaScript

Provider:

JavaScript

Advertisement

Answer

You misunderstood the purpose MessageBodyReader , it is used for the following purpose :

Contract for a provider that supports the conversion of a stream to a Java type. To add a MessageBodyReader implementation, annotate the implementation class with @Provider. A MessageBodyReader implementation may be annotated with Consumes to restrict the media types for which it will be considered suitable

Example : If you have a use case where you getting come custom format other than xml/json ,you want to provide your own UnMarshaller you can use messagebody reader

JavaScript

In webservice you can use this like ..

JavaScript

More Info : Custom Marshalling/UnMarshalling Example , Jersy Entity Providers Tutorial

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement