如何将 JAXB 类实例编组为其超类

发布于 2024-10-03 23:23:25 字数 1156 浏览 0 评论 0 原文

是否可以将 JAXB 带注释的类实例编组为其超类(这也是一个 JAXB 带注释的类)?

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BenamningTYPE", propOrder = {"benamningId"})
@XmlSeeAlso({MoreDetailedBenamningTYPE.class})
public class BenamningTYPE {
    ...
    @XmlElement(name = "BenamningId", required = true)
    protected IdentifierTYPE benamningId;
    ...
}

和扩展类型:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MoreDetailedBenamningTYPE", propOrder = {"modifyDetails"})
public class MoreDetailedBenamningTYPE extends BenamningTYPE {
    ...
    @XmlElement(name = "ModifyDetails", required = true)
    protected ModifyDetailsTYPE modifyDetails;
    ...
}

因此,如果这种情况:

BenamningTYPE b = new MoreDetailedBenamningTYPE();
...

那么我想将实例b编组为BenmaningTYPE以获取

<BenmaningTYPE>
    ...
</BenmaningTYPE>

And NOT< /strong>:

<MoreDetailedBenamningTYPE>
    ...
</MoreDetailedBenamningTYPE>

如果可能的话,这个元帅调用会是什么样子?

Is it possible to marshal a JAXB annotated class instance as its superclass (which is also a JAXB annotated class)?

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BenamningTYPE", propOrder = {"benamningId"})
@XmlSeeAlso({MoreDetailedBenamningTYPE.class})
public class BenamningTYPE {
    ...
    @XmlElement(name = "BenamningId", required = true)
    protected IdentifierTYPE benamningId;
    ...
}

And the extended type:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MoreDetailedBenamningTYPE", propOrder = {"modifyDetails"})
public class MoreDetailedBenamningTYPE extends BenamningTYPE {
    ...
    @XmlElement(name = "ModifyDetails", required = true)
    protected ModifyDetailsTYPE modifyDetails;
    ...
}

So if this scenario:

BenamningTYPE b = new MoreDetailedBenamningTYPE();
...

Then I would like to marshal the instance b as BenmaningTYPE to get

<BenmaningTYPE>
    ...
</BenmaningTYPE>

And NOT:

<MoreDetailedBenamningTYPE>
    ...
</MoreDetailedBenamningTYPE>

How would this marshal invoke look like, if possible?

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

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

发布评论

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

评论(1

难如初 2024-10-10 23:23:25

我还没有检查过,但我会先尝试一下:

new JAXBElement(new QName("BenmaningType"),
    BenManingTYPE.class, moreDetailedBenmaningTYPEInstance)

如果您要从 XML 模式生成类,请同时检查 可复制插件。您可以将数据从 MoreDetailedBenamningTYPE 实例复制到实例 BenmaningTYPE 并对其进行封送。

还有更多的可能性,但它们有点复杂。

I haven't checked it, but I'd try first:

new JAXBElement(new QName("BenmaningType"),
    BenManingTYPE.class, moreDetailedBenmaningTYPEInstance)

If you're generating classes from an XML Schema, check also the copyable plugin. You could the copy data from an instance of MoreDetailedBenamningTYPE to the instance BenmaningTYPE and marshal that.

There are more possibilities, but they're a bit more complex.

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