JAXB seems not to be able to set a fixed attribute value by default. Is this expected behavior, or something I'm doing wrong?
I have an xsd like:
<element name="AccountCategory" type="tns:Integer"></element>
<xs:complexType name="Integer">
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="e-dtype" fixed="int"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Marshalling a java object created with new produces:
<AccountCategory>5</AccountCategory>
Java:
com.sample.Integer val = new com.sample.Integer();
val.setValue(5);
parentObject.setAccountCategory(val);
I am able to manually set the attribute value and it works fine. Also if I just reset it to its own value it also works. Seems like the marshaller is not using the get method when generating the XML?
val.setEDtype(val.getEDtype());
Results in
<AccountCategory e-dtype="int">5</AccountCategory>
The generated .java below:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Integer", propOrder = {
"value"
})
public class Integer {
@XmlValue
protected int value;
@XmlAttribute(name = "e-dtype")
@XmlSchemaType(name = "anySimpleType")
protected String eDtype;
/**
* Gets the value of the value property.
*
*/
public int getValue() {
return value;
}
/**
* Sets the value of the value property.
*
*/
public void setValue(int value) {
this.value = value;
}
/**
* Gets the value of the eDtype property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getEDtype() {
if (eDtype == null) {
return "int";
} else {
return eDtype;
}
}
/**
* Sets the value of the eDtype property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setEDtype(String value) {
this.eDtype = value;
}