I know about the possibility how to turn on the formatting when using Marshaller. But I’m using Apache CXF (JAX-RS) and returning a response like return Response.ok(entity).build();.
I haven’t found any option how to format the output. How can I do it?
First off, the way to get formatted output of XML is to set the right property on the marshaller (typically JAXB when working with CXF, which is OK since JAXB does a creditable job). That is, somewhere you’re going to have something doing this:
The issue is that you don’t necessarily want to have all output formatted; it adds quite a bit to the overhead. Luckily, you’re already producing an explicit
Response, so we can just use more features of that:Another method is mentioned in this JIRA issue (itself closed, but that’s not so much of an issue for you):
This leads to code like this:
The CXF site discusses registration of interceptors.