jackson-dataformat-xml icon indicating copy to clipboard operation
jackson-dataformat-xml copied to clipboard

Add `FromXmlParser.Feature.RETAIN_ROOT_ELEMENT` to allow lossless round-trip via Tree Model

Open cowtowncoder opened this issue 4 years ago • 4 comments

Normally XML document like:

<root>
  <value>3</value>
</root>

would be exposed as equivalent to JSON

{ "value" : "3" }

since that is typically the straight-forward and suitable representation for databinding use.

But when reading "as a tree", into JsonNode, this will lose a small part of information, namely the name of root element. User has no way to access this information, and although technically we could store it for access, API would feel clunky.

So instead perhaps there should be an option to instead expose said document like so:

{
  "root" : {
     "value" : "3"
  }
}

This would be particularly useful when coupled with the recently added ToXmlGenerator.Feature.UNWRAP_ROOT_OBJECT_NODE (added via #441) as users could then get full round-tripping of XML documents.

Note: one potential problem we do have is the "too late" passing of format-feature flags -- it would be particularly gnarly problem here.

cowtowncoder avatar Jul 08 '21 21:07 cowtowncoder

Hi @cowtowncoder do not see this issue fixed in 2.13. Any plans in coming releases?

asharani-m avatar Dec 10 '21 01:12 asharani-m

@asharani-m We would need someone to tackle this, i.e. PRs most welcome.

Since it requires API addition, needs to go in 2.14.

cowtowncoder avatar Dec 11 '21 00:12 cowtowncoder