Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Jersey Client automatically encode POJO entities into application/x-www-form-urlencoded, or do I need to write custom MessageBodyWriter?

I am calling a RESTful web service using Jersey's Client class along with Jackson to handle serialization to/from JSON. I am also using the JSONConfiguration.FEATURE_POJO_MAPPING setting to have Jackson automatically serialize my POJOs to JSON.

The remote service I'm sending my POJO to consumes MediaType.APPLICATION_FORM_URLENCODED and produces MediaType.APPLICATION_JSON_TYPE.

Do I have to create my own MessageBodyWriter implementation to handle POJO serialization into application/x-www-form-urlencoded, or does Jersey provide an implementation that does this for me using my POJO annotations?

like image 318
Gabriel Bauman Avatar asked Aug 12 '11 03:08

Gabriel Bauman


1 Answers

Jersey does not have a support for converting arbitrary POJO's to application/x-www-form-urlencoded. It can convert instances of Form, or MultivaluedMap. So either your method would have to return one of these, or you will have to write your own MessageBodyWritter.

like image 184
Martin Matula Avatar answered Sep 25 '22 07:09

Martin Matula