Gabriel Bauman
Gabriel Bauman

Reputation: 2416

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?

Upvotes: 7

Views: 2007

Answers (1)

Martin Matula
Martin Matula

Reputation: 7989

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.

Upvotes: 6

Related Questions