jaxb 版本 2.0 不使用 xmlrootelement 中的 name 属性

发布于 2025-01-05 06:18:21 字数 224 浏览 4 评论 0原文

我已将 jaxb 库更新到版本 2.0。 我正在使用以下 jar,jaxb-api-2.0.jar 和 jaxb-imp-2.0.jar。 现在的问题是,它没有使用 @XmlRootElement(name="something")。 但在以前的库的帮助下,该 xml 在生成的 xml 中使用了定义的名称“something”。现在它采用驼峰式大小写的类名,而不是名称属性中定义的“某物”。这是最新的 jaxb 库的错误吗?请帮忙!

I have updated the jaxb library to version 2.0.
I am using the following jars, jaxb-api-2.0.jar and jaxb-imp-2.0.jar.
Now the problem is, it's not using the @XmlRootElement(name="something").
But with the help of previous library, the xml used the defined name "something" in the generated xml. Right now it's taking the class name in camel case instead of "something" defined in the name attribute. Is it a bug of latest jaxb library? Please help!

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

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

发布评论

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

评论(2

穿越时光隧道 2025-01-12 06:18:21

下面是一个可能有帮助的示例。 @XmlRootElement 注释将控制 XML 文档的根元素的名称。如果要控制内部元素的名称,可以使用 @XmlElement 注释。

SomeObject

package forum9272675;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="something")
public class SomeObject {

    private SomethingElse somethingElse;

    @XmlElement(name="something-else")
    public SomethingElse getSomethingElse() {
        return somethingElse;
    }

    public void setSomethingElse(SomethingElse somethingElse) {
        this.somethingElse = somethingElse;
    }

}

SomethingElse

package forum9272675;

public class SomethingElse {

}

输出

<?xml version="1.0" encoding="UTF-8"?>
<something>
    <something-else/>
</something>

Below is an example that may help. The @XmlRootElement annotation will control the name of the root element for the XML document. If you want to control the name of an inner element you can use the @XmlElement annotation.

SomeObject

package forum9272675;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="something")
public class SomeObject {

    private SomethingElse somethingElse;

    @XmlElement(name="something-else")
    public SomethingElse getSomethingElse() {
        return somethingElse;
    }

    public void setSomethingElse(SomethingElse somethingElse) {
        this.somethingElse = somethingElse;
    }

}

SomethingElse

package forum9272675;

public class SomethingElse {

}

Output

<?xml version="1.0" encoding="UTF-8"?>
<something>
    <something-else/>
</something>
请别遗忘我 2025-01-12 06:18:21

在我的子班中,我使用 @XmlRootElement(name="some-thing")。除此之外,当我使用 @XmlType(name="some-thing") 时,我的问题得到了解决!

In my child class I was using the @XmlRootElement(name="some-thing"). In addition to it, when I use @XmlType(name="some-thing") my problem got resolved!

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