-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Bad map keys can not be unmarshaled #523
Comments
Unfortunately it is not possible to escape element names in XML (unlike Character Data content) so it is not clear what could and should be done. One thing that would be possible would be to use some sort of name-mangling to automatically change names to perhaps:
Unfortunately the actual rules for XML name character validity are VERY complicated (I know, wrote 2 XML parsers, Woodstox and Aalto :) ) so often times it is easier to focus on low-hanging fruits. But if this was done, output would at least be well-formed. EDIT: just realized that this is focused on |
Alternatively, instead of trying to escape the keys, maybe maps could always be generated like this: <badMap>
<item>
<key>000</key>
<value>foo</value>
</item>
<item>
<key>111</key>
<value>bar</value>
</item>
</badMap> Of course, this is FAR more verbose than the original syntax, but it should work. Alternatively, maybe XML attributes could also be used like in the following example this? <badMap>
<item name="000">foo</item>
<item name="111">bar</item>
</badMap> Guaranted, I don't know the internals of Jackson, so I am not sure how easy that would be. |
I do realise that both options I have presented here are breaking format changes, which might be problematic. If this is indeed a problem, maybe this could be toggled via a <badMap>
<legalKey>Hello World!</legalKey>
<item name="item">I guess this would be a bit awkward but I guess it works...</item>
<item name="000">foo</item>
</badMap> I am not a huge fan of escaping / mangling characters since the main use case for me is serializing / deserializing Objects from and to a human readable format. |
Alas, even if So I don't think there is any way around either name-mangling or erroring out. |
My problem is, that I don't see a good way to reliably name-mangle something like
While this is certainly not ideal it is still far better than producing invalid XML.
Yeah, I didn't think about that one.
Here I would disagree, especially since I don't see how name-mangling could be made reversible and that there is the option of adding a new flag to opt into new behavior ( To solve this, my proposal would be:
This way, the resulting XML is still always easily readable, the serialization / deserialization process is 100% reversible, and If all this is not an option, than maybe instead of name mangling this could be done?
|
Correct: there is no way to make name-mangling reversible. For POJOs this is non-optimal but doable. But while both use logical structure of (JSON) Object for serialization, their handling is very different within And this is where the challenge wrt It might be possible to define new |
This commit introduces the `PROCESS_ESCAPED_MALFORMED_TAGS` and `ESCAPE_MALFORMED_TAGS` features that control whether invalid tag names will be escaped with an attribute. fixes FasterXML#523 fixes FasterXML#524
This commit adds an extendable `XmlTagProcessor` that is used for escaping invalid characters in XML tag names. fixes FasterXML#523 fixes FasterXML#524
Specifically map keys like
000
and111
will be marshaled as<000>
and<111>
, which can no longer be unmarshaled. Jackson should make sure to escape those keys correctly.Example:
jackson version: 2.13.2
The text was updated successfully, but these errors were encountered: