This is actually a feature, not bug. Almost all xml serializers do the same (Xslt outputters used with DOM, JDom, XOM). That However, it may be something that should be configurable, so that this escaping behavior could be disabled.
The main problem is this: since XML parsers must convert \r (Mac) and \r\n (Windows) linefeeds into canonical \n (Unix) when parsing, as per specification, one way to think about this is that if someone really wants to output char \r, they want to preserve it when parsed. The only way to do this is to quote \r as a character entity.
However, it is also possible that caller doesn't care about it getting normalized, just wants linefeeds to work better when viewed (which I assume is what you would prefer).
So it is pretty much impossible to handle both cases simultaneously.
If the alternative behavior (just leave \r chars as is, instead of character entities) is something you'd like to see, this can quite easily be added as a feature to XMLStreamWriter implementation (to be configured via XMLOutputFactory).
Assuming this would work, I can try to add this feature to 3.2.
This is actually a feature, not bug. Almost all xml serializers do the same (Xslt outputters used with DOM, JDom, XOM). That However, it may be something that should be configurable, so that this escaping behavior could be disabled.
The main problem is this: since XML parsers must convert \r (Mac) and \r\n (Windows) linefeeds into canonical \n (Unix) when parsing, as per specification, one way to think about this is that if someone really wants to output char \r, they want to preserve it when parsed. The only way to do this is to quote \r as a character entity.
However, it is also possible that caller doesn't care about it getting normalized, just wants linefeeds to work better when viewed (which I assume is what you would prefer).
So it is pretty much impossible to handle both cases simultaneously.
If the alternative behavior (just leave \r chars as is, instead of character entities) is something you'd like to see, this can quite easily be added as a feature to XMLStreamWriter implementation (to be configured via XMLOutputFactory).
Assuming this would work, I can try to add this feature to 3.2.