jackson-dataformat-xml icon indicating copy to clipboard operation
jackson-dataformat-xml copied to clipboard

XML: Allow adding <?xml-stylesheet ...>

Open OndraZizka opened this issue 4 years ago • 2 comments

Describe the solution you'd like Allow adding to the resulting XML.

Usage example I want to serialize Java POJOs to XML in Spring REST endpoint, but include XSLT reference so that the browsers render it as HTML.

Additional context The only similar feature I found is a flag WRITE_XML_DECLARATION.

ObjectMapper mapper = builder.createXmlMapper(true).build();
    ((XmlMapper) mapper).enable(ToXmlGenerator.Feature.WRITE_XML_DECLARATION);
    return new MappingJackson2XmlHttpMessageConverter(mapper);
}

OndraZizka avatar Feb 10 '21 18:02 OndraZizka

(will move to correct repo)

cowtowncoder avatar Feb 10 '21 21:02 cowtowncoder

Right now the only way would be to explicitly contruct either underlying XMLStreamWriter, and write both xml declaration and style sheet PI (assuming it comes before root element); or, to construct ToXmlGenerator similarly, use writeRaw() to force output of declaration.

It would be good to add new mechanism(s), I think #150 is related to this. Not sure of the best way to model this; I don't think a feature flag will work well enough, but while configuring XmlMappers is possible via new Builder API, this may be something where per-write option would be preferable.

I hope to tackle something in this space for 2.13, tagging.

cowtowncoder avatar Feb 10 '21 21:02 cowtowncoder