Foo.java
@XmlElementWrapper(name = "Foos", nillable = Config.FOO_NILLABLE)
@XmlElement(name = "Foo")
public List<String> foos;
Config.java
public static final Boolean FOO_NILLABLE = true;
// works
public static final Boolean FOO_NILLABLE = loadConfigValueFromDatabase();
// doesn't work - attribute value must be constant
Desired outcome when foos null (or empty)
config = true
<parent>
<foos xs:nil="true">
</parent>
config = false
<parent>
</parent>
I have Eclipselink 2.7.8 on this project. I’m open to other ways of achieving this outcome but the crux is that once I make the changes this behaviour needs to be configurable rather than depending on further code changes.
UPDATE: The exact implementation of dynamically setting nillable
is not essential, but I just need to be able to find a way to selectively switch between <foos>
appearing as xs:nil="true"
and it not appearing at all