JAXB编组 - 扩展现有类 [英] JAXB Marshalling - extending an existing class

查看:96
本文介绍了JAXB编组 - 扩展现有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用JAXB通过XML创建一系列Java对象,这些对象都扩展了已创建的公共基类(不使用JAXB)。例如,假设我有以下我想要生成的JAXB类:

I am in need of creating a series of Java objects via XML using JAXB that all extend a common base class that is already created (not using JAXB). For example, let's say I have following JAXB classes that I am trying to generate:

Penguin.xml  -> Penguin.java
Robin.xml -> Robin.java
Cardinal.xml -> Cardinal.java

我已经有一个名为的现有基类Bird.java 我希望上面的三个类能够扩展。

I already have an existing base class called Bird.java that I wish the three classes above to extend.

最好的方法是什么?

感谢您的帮助!

推荐答案

这很简单:您需要创建一个包含以下内容的JAXB绑定文件:

That is very simple: you need to to create a JAXB binding file with following contents:

<jaxb:bindings version="1.0"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
>

    <jaxb:globalBindings>
        <!-- All beans should extend this base class: -->
        <xjc:superClass name="org.mycompany.common.Bird" />
    </jaxb:globalBindings>

</jaxb:bindings>

您可以找到关于此选项(以及其他甜食)的更多信息在其他地方

More information on this option (and other sweet things) you can find here.

这篇关于JAXB编组 - 扩展现有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆