-
-
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
Allow specifying encodings other than UTF-8 in XML declaration written #315
Comments
Ah. Yes, I see. So although underlying writer may actually use different encoding, xml declaration claims it is UTF-8. That's not good. |
Additionaly, XmlFactory outputs utf-8 only:
|
@saimonsez That is intentional however (partly since there is no mechanism to pass non-Unicode encodings); caller is expected to create However, I hope to introduce a mechanism to allow users to create document "header" (xml declaration and/or DOCTYPE declaration) via |
I see, thank you for clarification. In my case, the caller is spring-web (AbstractJackson2HttpMessageConverter) without a chance to configure an enocding other than unicode, so I am stuck again. Are you by chance involved with springs integration of jackson? |
I just created spring-projects/spring-framework#25076 which is related to this issue (if jackson is used with spring). |
I am only involved whenever Spring folks file bugs, but do not know their code base (and they don't use, I think, Jackson JAX-RS provider). |
This is still moved for 2 years from Any stupid workaround would be great. |
@kromit You are absolutely welcome to provide a fix as you seem to need it. |
@cowtowncoder I've looked into this and I would break significantly more things on the way, than I would fix. 🙈
|
Couple of possibly helpful pointers:
The idea with #150 (which I really would like to get in 2.12 if I have time) would be to allow registering a writer callback that would write all pre-amble events (xml declaration and/or DOCTYPE) the way caller wants. Conceptually simple just need to think of a way to do that in a way that fits with format-specific handling of Jackson's databind (most API is format-agnostic). |
@cowtowncoder is there any appetite to take this on for v2.16? If I was to look at this, I'd prefer not to use custom declaration handling and to concentrate on allowing this module to create XMLStreamWriter instances that could be created with other encodings. In pseudocode, a user might be able to do this
The We can decide afterwards if it makes sense to support this on the String/Reader write methods. If you look at XmlFactory, there is some support for I have a couple of changes here but the use of JsonEncoding is not a good place to start. And in practice, users don't typically create their own generators and use higher level methods like writeValueAsString/writeValueAsBytes. |
@pjfanning Agreed, So I am open to alternate takes here; I do not have current specific plans (or time) to tackle this myself, so should not try to dictate solution. But will definitely give feedback :) |
@cowtowncoder the workaround in https://github.com/FasterXML/jackson-dataformat-xml/blob/5063969ec78dcfe076ac3356fdd1eefec7aedcdc/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/IncrementalWritingTest.java - does this only work with the v2.17 future release? |
@pjfanning I think using 2.17 adds convenience factory methods but fundamentally those are not necessary I think. This isn't super convenient mechanism of course, but at least makes certain things possible. |
The
UTF-8
encoding is hard coded in theToXmlGenerator
source code:Once
ToXmlGenerator
isfinal
, there might not be an easy way to have other encodings such asISO-8859-1
:See this question in Stack Overflow for reference.
The text was updated successfully, but these errors were encountered: