-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] Support Encoding option when writing XML #593
base: 2.17
Are you sure you want to change the base?
Conversation
pjfanning
commented
May 1, 2023
•
edited
Loading
edited
- relates to Allow specifying encodings other than UTF-8 in XML declaration written #315
- so far, only supporting this for binary formats (OutputStream, File, byte[])
- will later see if something similar is useful for other formats
1e0ec22
to
96ee4e9
Compare
@cowtowncoder when you get a chance, could you review the work in progress? If the new XmlMapper methods look ok, I can extend the coverage on them. |
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
|
||
public class TestCharset extends XmlTestBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, probably will want to check Latin-1 (ISO-8859-1) as well.
I guess this is WIP so probably were already planning (ditto for basic UTF-8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can add more tests, including for other charsets. I guess that the point at this stage is try to agree an API approach first. Keeping the number of test cases low at this point means it's easier for me to adjust the API (without the need to then rewrite all the tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, agreed.
Makes sense for the most part. The only thing I am not sure how I feel about is addition of more I guess if we were to consider extending support for encodings to be core part of So maybe adding methods here only first makes sense. |
I'm not sure about the idea to force users to create a One alternative approach would be to add a setter on XmlMapper or XmlFactory where users can set a default charset. The problem here is that if users need to create XML outputs with different charsets that they would need to create an XmlMapper instance for every charset that they need to support. We could have this setting on XmlMapper and allow it to be changed just before any 'write' call. This goes against the aim of making Mapper instances immutable but it might be the tidiest approach to allowing multiple charsets without having to add quite a few new 'write' methods. If we keep the current approach in this PR of adding new write methods, we could also add them to a new XmlWriter subclass of ObjectWriter. |
Yes, that is problematic as well.
That does not seem right either, although of the two, Could use Builder(); but could not set it on per-call basis.
Unfortunately when I tried to make I need to think about this some more. I am not dead set against new methods in |
Update XmlFactory.java Update XmlFactory.java
481108a
to
a4a9400
Compare
@cowtowncoder I added an XmlWriter to this PR - an extension to ObjectWriter but with the additional write methods that I added to XmlMapper. The methods on XmlMapper that return an ObjectWriter will return an XmlMapper that can be cast to get access to the extra methods. I also added a If these API changes are ok, I can add extra test coverage to this PR. |
@cowtowncoder is this PR worth continuing with? |
Good draft, really needed. |
Ok, so:
given this I don't think this PR as-is will be worth pursuing. But I think it's useful to keep open until an alternative path is found. |