JAXB returns an empty XML attribute as 0, and that's fine, but I have a requirement to keep it as zero. It seems I cannot change the DataConverterImpl class for a custom implementation. What can 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 compiling the xjc schema, I got a class with the following:
@XmlAttribute(name = "Count") protected Integer passengerCount;
During XML, parse parseInt() is called from DataConverterImpl.class from Sun (Oracle), whose code is below, your neve is 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; }
java jaxb
kot
source share