JAXB treets empty int XML attribute as 0, which is fine with me, but I've got requirement to store it as a null. Seems I can't change DataConverterImpl class to custom implementation. What could be done if at all?
<xs:attribute name="Count" type="Integer0to999" use="optional">
<xs:simpleType name="Integer0to999">
<xs:annotation>
<xs:documentation xml:lang="en">Used for Integer values, from 0 to 999 inclusive</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="999"/>
</xs:restriction>
</xs:simpleType>
After xjc schema compilation I got class with the following:
@XmlAttribute(name = "Count")
protected Integer passengerCount;
During XML parse parseInt()
get called from DataConverterImpl.class
from Sun(Oracle) which code is below, your neve going to get null from this code :
public static int _parseInt(CharSequence s) {
int len = s.length();
int sign = 1;
int r = 0;
for( int i=0; i<len; i++ ) {
char ch = s.charAt(i);
if(WhiteSpaceProcessor.isWhiteSpace(ch)) {
// skip whitespace
} else
if('0'<=ch && ch<='9') {
r = r*10 + (ch-'0');
} else
if(ch=='-') {
sign = -1;
} else
if(ch=='+') {
; // noop
} else
throw new NumberFormatException("Not a number: "+s);
}
return r*sign;
}