开发者

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

开发者 https://www.devze.com 2023-03-21 01:20 出处:网络
Currently I have my Jersey (JAX-RS) Webservice return an JAXB annotated Object with a simple @Produces(\"text/xml\") in my Webservice me开发者_Python百科thod. Unfortunately the output looks rather mes

Currently I have my Jersey (JAX-RS) Webservice return an JAXB annotated Object with a simple @Produces("text/xml") in my Webservice me开发者_Python百科thod. 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?


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>


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:

  • Validate JAXBElement in JPA/JAX-RS Web Service
0

精彩评论

暂无评论...
验证码 换一张
取 消