4

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?

Dominik
  • 4,718
  • 13
  • 44
  • 58

2 Answers2

4

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>
Artefacto
  • 96,375
  • 17
  • 202
  • 225
  • 1
    By now (Jersey 2.12) the flag has changed its name to jersey.config.xml.formatOutput . It can be found in the class MessageProperties – Shirky Sep 23 '14 at 14:41
1

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:

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • I am sorry but I somehow dont understand how to create my own JAXB Marshaller that will format my output. – Dominik Jul 30 '11 at 16:32
  • 2
    As far as I see it I have to make my own MessageBodyWriter tat sets FEATURE_FORMATTED to true, but I cant grasp how to. – Dominik Jul 30 '11 at 16:48