JAXB treets 빈 int XML 속성은 0으로 나와 괜찮지 만 null로 저장할 필요가 있습니다. DataConverterImpl 클래스를 사용자 정의 구현으로 변경할 수없는 것 같습니다. 그렇다면 무엇을 할 수 있습니까? 코드는 다음과 같습니다 일 (오라클)에서 DataConverterImpl.class
에서 parseInt()
을 호출되는 구문 분석 XML 동안JAXB treets empty int XML 속성 0으로 0
@XmlAttribute(name = "Count")
protected Integer passengerCount;
, 당신의 만년설이가는 :
<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>
xjc를 스키마 컴파일 후 나는 다음과 클래스를 가지고 이 코드에서 null을 얻으려면 :
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;
}