Skip to content

xsi:nil is implemented in a strange way #1840

@laeubi

Description

@laeubi

I currently hit a "bug" that really gives me a hard time to figure out:

If one reads a document and an element has xsi:nil set, this results in this element never changing its value.

This is because jakarta.xml.bind.JAXBElement.isNil() returns true whenever value is null or nil is true.

Now assume you de-serialize a document with something like:

<S xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

then call JAXBElement.setValue("balbla") with a non null value then isNil will return still true but the serializer writes it out as <S>balbla</S> (what is of course desired!)

I have no good idea how to really mitigate this, but it makes the method JAXBElement.isNil() almost useless to be used in client code, because:

  1. either nil is false in which case it return true if the value is null
  2. if nil is true it always return true regardless of what the value is

So from a code point of view I can of course write the value but the result is actually dependent on if the value is non null when serialize it. Reading the value on the other hand gives me nothing, as it reflects not the value of the attribute, so actually everywhere i would need to use JAXBElement#getValue anyways to be really sure what the outcome will be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions