FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
561 stars 221 forks source link

Serialize empty tags to actual json array/object #642

Open Croway opened 4 months ago

Croway commented 4 months ago

Hello @cowtowncoder , I think it would be nice to serialize empty tag into actual array/objects (in some cases), not text value, in particular, as you can see from the added test case <name><first/><last>[]</last></name> will be serialized as {"first":[],"last":"[]"} when using JsonNode, the empty tag first is serialized as an empty json array, not a text value.

But I feel like that my solution is a bit hacky, do you have any hint?

Once https://github.com/FasterXML/jackson-dataformat-xml/pull/640 is merged I'll rebase this one.

cowtowncoder commented 4 months ago

Yeah I am not sure I'm inclined to add support for this. Jackson, in general, tries to steer clear of 2 general areas:

  1. Validation of logical content (aside from well-formedness and needing to map between data, Java Objects) -- Bean Validation API to be used for validation, constraints-checking
  2. Structural transformations

Obviously there's some amount of functionality that overlaps here, but in general complexity of structural transformations is such, for streaming/incremental reading/writing that it seems best left out. Things that are needed are already too complex.