小编kot*_*kot的帖子

JAXB将empty int XML属性替换为0

JAXB将empty int XML属性替换为0,这对我很好,但是我需要将它存储为null.似乎我无法将DataConverterImpl类更改为自定义实现.如果有的话可以做些什么?

<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>
Run Code Online (Sandbox Code Playgroud)

在xjc架构编译之后,我得到了以下类:

 @XmlAttribute(name = "Count")
    protected Integer passengerCount;
Run Code Online (Sandbox Code Playgroud)

在从Sun(Oracle)parseInt()调用XML解析时 DataConverterImpl.class,代码如下,你的neve将从这段代码中获取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') …
Run Code Online (Sandbox Code Playgroud)

java jaxb

7
推荐指数
1
解决办法
4199
查看次数

标签 统计

java ×1

jaxb ×1