gpt4 book ai didi

jaxb - 如何在子类上使用 JAXB @XmlValue?

转载 作者:行者123 更新时间:2023-12-03 21:40:27 30 4
gpt4 key购买 nike

我想要这样的 XML:

<simple>Foo</simple>

我可以通过一个看起来像这样的 JAXB 类成功地做到这一点:
@XmlRootElement(name="simple")
class Simple {
@XmlValue
public String contents;
}

但是现在我需要使 Simple 类成为另一个类的子类,如下所示:
@XmlRootElement(name="simple")
class Simple extends OtherClass {
@XmlValue
public String contents;
}

失败了 @XmlValue is not allowed on a class that derives another class.我不能轻易地重构父类(super class)(因为我们在包装类上使用 @XmlElementRef 的方式)。是否有一种解决方法可以让我注释我的子类以生成那个简单的 XML?

最佳答案

接受的答案对我不起作用。

一切都很好,但我还需要将 @XmlTransient 添加到父类(super class)

关于jaxb - 如何在子类上使用 JAXB @XmlValue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8098274/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com