Skip to content

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

Open
@cowtowncoder

Description

@cowtowncoder

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pr-neededFeature request for which PR likely needed (no active development but idea is workable)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions