Search code examples
javaxmljibx

Jibx - create closing tags when marshalling empty values to XML


When marshalling an empty value, the XML generated looks something like:

<some_data>
    <required_tag_with_data>Some data</required_tag_with_data>
    <required_tag_without_data>
</some_data>

The output I'd like to see, however, is more like this:

<some_data>
    <required_tag_with_data>Some data</required_tag_with_data>
    <required_tag_without_data />
</some_data>

or this:

<some_data>
    <required_tag_with_data>Some data</required_tag_with_data>
    <required_tag_without_data></required_tag_without_data>
</some_data>

In the binding I've tried setting usage="required" and nillable="true" but that results in:

<some_data>
    <required_tag_with_data>Some data</required_tag_with_data>
    <required_tag_without_data xsi:nil="true">
</some_data>

Thanks in advance :)


Solution

  • It turns out that Jibx is not at fault.

    I am using a Chrome plugin called Dev HTTP Client (https://plus.google.com/104025798250320128549) to view the output XML. The plugin, it appears, applies some formatting to the XML but then drops off the closing forward slash in the scenario described above.

    When viewing the raw output (in my IDE's debugger) it is as expected.

    I have raised a bug report with the developer of DHC.