为什么 JAXB (jaxb2-maven-plugin) 会跳过此属性?

发布于 2024-11-26 14:50:10 字数 1668 浏览 2 评论 0原文

jaxb2-maven-plugin 1.3 跳过对象的属性。我无法修改 XSD。在XSD(片段)中:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="classA" type="classA" substitutionGroup="classSubA"/>

    <xs:complexType name="complexClassA" mixed="true">

    <xs:attribute name="attA">
        <xs:annotation>
            <xs:appinfo>
                <moProperty value="classA:attA"/>
                <label value="Attribute A" default="true"/>
                <externAccess value="readWrite"/>
            <description value="NO COMMENTS"/>
        </xs:appinfo>
    </xs:annotation>
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="off"/>
            <xs:enumeration value="on"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

<xs:attribute name="id" type="xs:unsignedInt">
    <xs:annotation>
        <xs:appinfo>
            <moProperty value="myClassB:id"/>
            <label value="Id" default="true"/>
            <externAccess value="readWrite"/>
            <description value="NO COMMENTS"/>
        </xs:appinfo>
    </xs:annotation>
</xs:attribute>
</xs:schema>

生成的Java对象(片段):

public class ComplexClassA {
    @XmlSchemaType(name = "unsignedInt")
    protected Long id;
}

为什么它没有生成attA成员?

可能是内联枚举的原因吗?

谢谢。

乌多.

jaxb2-maven-plugin 1.3 skips an attribute from an object. I cannot modify the XSD. In the XSD (fragment):

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="classA" type="classA" substitutionGroup="classSubA"/>

    <xs:complexType name="complexClassA" mixed="true">

    <xs:attribute name="attA">
        <xs:annotation>
            <xs:appinfo>
                <moProperty value="classA:attA"/>
                <label value="Attribute A" default="true"/>
                <externAccess value="readWrite"/>
            <description value="NO COMMENTS"/>
        </xs:appinfo>
    </xs:annotation>
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="off"/>
            <xs:enumeration value="on"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

<xs:attribute name="id" type="xs:unsignedInt">
    <xs:annotation>
        <xs:appinfo>
            <moProperty value="myClassB:id"/>
            <label value="Id" default="true"/>
            <externAccess value="readWrite"/>
            <description value="NO COMMENTS"/>
        </xs:appinfo>
    </xs:annotation>
</xs:attribute>
</xs:schema>

The Resulting Java Object (fragment):

public class ComplexClassA {
    @XmlSchemaType(name = "unsignedInt")
    protected Long id;
}

Why it is not generating the attA member?

Might it be cause the inline enumeration?

Thank you.

Udo.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情丝乱 2024-12-03 14:50:10

您能否提供一个完整的 XML 架构来演示该问题?下面是我尝试过的,一切似乎都按预期工作。


当我在以下 XML 模式上运行 XJC 时:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/Foo" xmlns="http://www.example.org/Foo" 
    elementFormDefault="qualified">

    <xs:complexType name="complexClassA" mixed="true">

        <xs:attribute name="attA">
            <xs:annotation>
                <xs:appinfo>
                    <moProperty value="classA:attA"/>
                    <label value="Attribute A" default="true"/>
                    <externAccess value="readWrite"/>
                    <description value="NO COMMENTS"/>
                </xs:appinfo>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                <xs:enumeration value="off"/>
                <xs:enumeration value="on"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>

        <xs:attribute name="id" type="xs:unsignedInt">
            <xs:annotation>
                <xs:appinfo>
                    <moProperty value="myClassB:id"/>
                    <label value="Id" default="true"/>
                    <externAccess value="readWrite"/>
                    <description value="NO COMMENTS"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:attribute>

    </xs:complexType>

</xs:schema>

我按预期得到以下类:

package org.example.foo;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "complexClassA", propOrder = {
    "content"
})
public class ComplexClassA {

    @XmlValue
    protected String content;
    @XmlAttribute
    protected String attA;
    @XmlAttribute
    @XmlSchemaType(name = "unsignedInt")
    protected Long id;

    public String getContent() {
        return content;
    }

    public void setContent(String value) {
        this.content = value;
    }

    public String getAttA() {
        return attA;
    }

    public void setAttA(String value) {
        this.attA = value;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long value) {
        this.id = value;
    }

}

Can you provide a complete XML schema that demonstrates the problem? Below the line is what I have tried and everything appears to work as expected.


When I run XJC on the following XML schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/Foo" xmlns="http://www.example.org/Foo" 
    elementFormDefault="qualified">

    <xs:complexType name="complexClassA" mixed="true">

        <xs:attribute name="attA">
            <xs:annotation>
                <xs:appinfo>
                    <moProperty value="classA:attA"/>
                    <label value="Attribute A" default="true"/>
                    <externAccess value="readWrite"/>
                    <description value="NO COMMENTS"/>
                </xs:appinfo>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                <xs:enumeration value="off"/>
                <xs:enumeration value="on"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>

        <xs:attribute name="id" type="xs:unsignedInt">
            <xs:annotation>
                <xs:appinfo>
                    <moProperty value="myClassB:id"/>
                    <label value="Id" default="true"/>
                    <externAccess value="readWrite"/>
                    <description value="NO COMMENTS"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:attribute>

    </xs:complexType>

</xs:schema>

I get the following class as expected:

package org.example.foo;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "complexClassA", propOrder = {
    "content"
})
public class ComplexClassA {

    @XmlValue
    protected String content;
    @XmlAttribute
    protected String attA;
    @XmlAttribute
    @XmlSchemaType(name = "unsignedInt")
    protected Long id;

    public String getContent() {
        return content;
    }

    public void setContent(String value) {
        this.content = value;
    }

    public String getAttA() {
        return attA;
    }

    public void setAttA(String value) {
        this.attA = value;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long value) {
        this.id = value;
    }

}
南七夏 2024-12-03 14:50:10

转到

org.jvnet.jaxb2.maven2 后
maven-jaxb2-plugin

一切正常。

感谢您抽出时间。

After going to

org.jvnet.jaxb2.maven2
maven-jaxb2-plugin

Everything is working fine.

Thank you for your time.

︶ ̄淡然 2024-12-03 14:50:10

您使用什么 JAXB 版本?内联枚举应正确转换为 Java 枚举。

您可以尝试在属性定义之外定义 simpleType,这可能会有所帮助。

What JAXB version are you using? The inline Enumeration should be turned into an Java enum correctly.

You could try to define the simpleType outside the Attribute definition, that would help probably.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文