jaxb 不生成具有基本整数的枚举

2022-01-09 00:00:00 xsd java maven jaxb

我有以下 xsd:

<xs:simpleType name="resultcode">
    <xs:restriction base="xs:integer">
        <xs:enumeration value="0" id="Approved_no_error">
            <xs:annotation>
                <xs:appinfo>
                    <jxb:typesafeEnumMember name="Approved_no_error"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:enumeration>

JAX-B 什么都不做,没有错误,没有警告,只是不会生成这个类.如果将基数从 xs:integer 更改为 xs:string 就可以了.但我需要的正是整数值.

JAX-B just does nothing, no errors, no warnings just doesn't generate this class. If change base from xs:integer to xs:string then it's ok. But I need exactly integer values.

我用 maven 生成类:

I generate classes with maven:

<groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>AuthGateway</id>
            <goals>
                <goal>xjc</goal>
            </goals>

问题 2.JAX-B 和 IDE (IDEA) 不允许在 id 属性中使用空格.为什么?

And question 2. JAX-B and IDE (IDEA) doesn't allow whitespaces in id attrribute. Why?

<xs:enumeration value="0" id="Approved_no_error"> - 好的
<xs:enumeration value="0" id="Approved no error"> - 不行

这是正确的行为吗?

推荐答案

您可以使用外部绑定文件来获取您正在寻找的行为:

You can use an external binding file to get the behaviour that you are looking for:

  • 带数值的JAXB枚举
  • http://blog.bdoughan.com/2011/08/jaxb-and-enums.html

相关文章