-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
@JsonAnySetter Mangles Nested Xml Elements and Xml Attributes During Serialization #629
Comments
Ok. First of all: yes, your use case makes sense, and your approach as well. Unfortunately round-tripping of XML without intermediate POJO is difficult and specifically there is no way to retain "attribute-ness" of input. As such it is not possible to retain that aspect currently, without having a POJO that indicates which properties would be serialized as attributes. Having said that those empty tags ( One possible improvement, conceptually, would be to add some sort of "Native XML" value type, to which XML subsections could be mapped, and that would serialize as XML. I don't have a good idea of how it'd work, problem being that Other than that we could try to at least figure out how to get rid of "empty tags". For that a minimal unit test would be nice, to reproduce the problem more concisely. |
Thanks for the quick reply and all you do with this project! Some sort of For now, I'll plan to intercept the raw XML input (before it goes through any parser) and echo its contents back via the response to the user (will require a CWE encoder to prevent abuse). I dislike the idea of this approach, so in the future, I'll see if I can't give the custom deserializer another shot, and post the code to this issue. |
Native type would have to be value of I agree that in the meantime it will be necessary to use a work-around, and that may indeed be sub-optimal. |
Realized this is in wrong repo, will transfer. |
I apologize in advance if there is already a bug opened for this condition (or if I am approaching this the wrong way) - my search-fu failed to turn up anything similar.
I have a situation where I need deserialize XML to a POJO, and at the end of it all I need to serialize the request back to XML and return it as part of the response. I only need to process a portion the fields. I'd rather not map out all unused fields on the POJO, as this would require constantly updating the application as the end-user's generation of the request schema grows over time.
Describe the bug
I'm attempting to use
@JsonAnySetter
to capture the unmapped fields during deserialization, and@JsonAnyGetter
to serialize them on the way back out.It works fine for simple values (e.g.
<some-unmapped-field>hello</some-unmapped-field>
. But when the unmapped field includes attributes (.e.g.<some-unmapped-field id = "one">hello</some-unmapped-field>
or nested XML elements (e.g.<some-unmapped-field><a>1</a><b>2</b></some-unmapped-field>
, the serialized output becomes completely mangled.Version information
com.fasterxml.jackson.core:jackson-annotations:2.13.3
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.3
To Reproduce
The POJO:
The input XML:
The output XML:
Expected behavior
I would expect the attributes/elements to be kept through the deserialization / serialization process.
Additional context
String
(output is empty) andcom.fasterxml.jackson.databind.JsonNode
(throws JsonMappingException).@JsonRawValue
, but from what I've read that only affects serialization, and has no effect on deserialization. This has been consistent with my experiments.JsonParser
seems too-JSON oriented, ultimately requiring the input XML to cleanly map to JSON - my guess would be this is why I'm having this issue in the first place.Thanks for looking!
The text was updated successfully, but these errors were encountered: