JAXB Marshalling - Extending an Existing Class

I need to create a series of Java objects via XML using JAXB, which extend a common base class that has already been created (without using JAXB). For example, suppose I have the following JAXB classes that I am trying to create:

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

I already have a base class called Bird.java , which I want the three classes to extend above.

What is the best way to do this?

Thanks for your help!

+4
source share
1 answer

It is very simple: you need to create a JAXB binding file with the 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> 

You can find more about this option (and other nice things) here .

+7
source

Source: https://habr.com/ru/post/1397457/


All Articles