Java JAXB and inheritance

I want to create a list of different class types that inherit from the same superclass.
I start with the xsd file, and I want to create java classes in a downloadable xml boot file that has list nodes.
My problem is to define xsd which will create java classes.

I am using the eclipse JAXB 2.0 plugin.

In the end, I want to have one List<superClass>.
Can I do this with simple JAXB?

+3
source share
1 answer

I do not understand why you want to start with xsd if you do not already have it. If you are free with respect to the scheme, it will start with java code and generate XSD.

:

@XmlElements({
    @XmlElement(name = "child1", type = Child1.class),
    @XmlElement(name = "child2", type = Child2.class),
    @XmlElement(name = "child3", type = Child3.class)})
private final List<IChild> children = new ArrayList<IChild>();

IChild - superClass. XSD-, .

+11

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


All Articles