Closed M4NN3 closed 1 year ago
I took a look at the source code and it looks like this behavior is caused by https://github.com/FasterXML/jackson-dataformat-xml/blob/2.14/src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java#L619.
From my understanding, the intention was to add a new line feed to separate entities outside of the root element (that is, in prolog or epilog), but it is also added after the document body in the scenario in which a document doesn't contain an epilog.
I am not sure if it was intended to behave in this way or if it can be considered a bug.
@Roomka if anyone could provide a test to show that with change to remove extra linefeed:
I'd be happy to merge said PR. I don't have time to do this myself right now but would be happy to code review, get merged.
Timing now is pretty tight -- I am about to publish 2.14.0 final in 2-3 days -- but regardless of whether it'd go in 2.14.0 or later (I think this'd be ok for a patch... maybe), it'd be nice improvement.
Hi @cowtowncoder,
not sure if I am missing something but from my understanding, there is no way to add the epilog in an object mapped by the object mapper.
I opened a PR https://github.com/FasterXML/jackson-dataformat-xml/pull/554 removing the part of the code that adds extra linefeed and updating the unit test affected by that change accordingly.
Ah. Yes, you are right, there is no way to add prolog or epilog stuff quite yet. Thank you for #554 -- I'll try to have a look soon, but am just bit swamped at work. But I'll get there eventually. :)
As per my notes on #546, I would want a full reproduction here, to make sure problem (if any!) is understood.
Basically: with indentation I
Ok as far as I can see this is actually behaving as I would expect.
To change behavior what you can do is to sub-=class DefaultXmlPrettyPrinter
and override method to do nothing:
public void writePrologLinefeed(XMLStreamWriter2 sw) throws XMLStreamException { }
This would change serialization so that no linefeeds would be added before opening root element or after closing one.
In theory it could be possible to make this configurable but it would get bit tricky, esp. if was to go through XmlMapper
.
I will close this as "not a bug" for now: to request configurability it'd be good file a new issue with reference to this one as context.
XmlMapper, when using
writerWithDefaultPrettyPrinter
and writing value to a new fle is adding an empty line at the end of the file. This is not happening when usingwriteValueAsString