JAXB treets vuoto int XML attributo come 0, che va bene per me, ma ho bisogno di memorizzarlo come null. Sembra che non possa cambiare la classe DataConverterImpl in implementazione personalizzata. Cosa si potrebbe fare se non del tutto?JAXB treets vuoto int XML attributo come 0
<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>
Dopo la compilazione dello schema xjc ho avuto classe con il seguente:
@XmlAttribute(name = "Count")
protected Integer passengerCount;
Durante XML analizzano parseInt()
ottenere chiamato da DataConverterImpl.class
da Sun (Oracle), che il codice è al di sotto, la vostra neve in corso per ottenere nulla da questo codice:
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;
}