Dominik
Dominik

Reputation: 4768

Java: Jersey (JAX-RS) and JAXB_FORMATTED_OUTPUT with annotation?

Currently I have my Jersey (JAX-RS) Webservice return an JAXB annotated Object with a simple @Produces("text/xml") in my Webservice method. Unfortunately the output looks rather messy because its not formatted with breaks and spaces.

Is there an annotation I can use like RESTeasy's @Formatted

or

how do I implement a marshaller, and where?

Upvotes: 4

Views: 1605

Answers (2)

Artefacto
Artefacto

Reputation: 97815

In Jersey, you can add an init parameter to its servlet:

<init-param>
    <param-name>com.sun.jersey.config.feature.Formatted</param-name>
    <param-value>true</param-value>
</init-param>

Upvotes: 4

bdoughan
bdoughan

Reputation: 148977

There is probably such an annotation in Jersey, but if there isn't you could leverage the JAX-RS concept of a MessageBodyWriter and leverage the JAXB Marshaller directly. Below is a link to an answer I gave where a MessageBodyReader was leveraged in order to set schema validation on a JAXB Unmarshaller:

Upvotes: 1

Related Questions