There is little problem with JAXB.
Given:
default value that is in annotations works only after unmarshalling.
unmarshal this
and you will get object with default values (-1, -1.0, "Default")
If you want set default values to marshalling, you should do this
public class Document {
@XmlElement(name = "d_int", defaultValue = "-1")
protected int dInt = 100;
@XmlElement(name = "d_double", defaultValue = "-1.0")
protected double dDouble = -100;
@XmlElement(name = "d_string", required = true, defaultValue = "Default")
protected String dString = "def";
...
}
jaxb generate default values only for unmarshalling