users@jaxb.java.net

diferentiating between non-existent element and element with null value

From: davy123 <david.vidrih_at_marand.si>
Date: Wed, 9 Jan 2008 02:05:29 -0800 (PST)

I would like to use JAXB do differentiate between non-existent element and
element with null value.


I managed to do this when UNmarshalling XML-s with:
- setting accessor type to NONE,
- setting fields to some unique value (private static final),
- annotating getters,
- setting them nillable=true and
- isSet feature checking equality to mentioned unique value with ==
Example:
    private static final String DEFAULT_STRING = new
String("DEFAULT_STRING");
    
    private String a = DEFAULT_STRING;

    @XmlElement(name = "a", nillable = true)
    public String getA() { return a; }

    public void setA(String value) { this.a = value; }

    public boolean isSetA() { return a != DEFAULT_STRING; }

Unmarshalling of XML without the 'a' element causes isSetA() returning
false, unmarshalling the 'a' with xsi:nil="true" causes isSetA() returning
true and getA() returning null.


The problem is the marshalling, does anyone know how to achieve marshalling
of a property only when you want (for example when isSet returns true, which
I have not managed to put it to work)?
-- 
View this message in context: http://www.nabble.com/diferentiating-between-non-existent-element-and-element-with-null-value-tp14708064p14708064.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.