I have an XML file in the following form:
<persons>
<person>
<firstname>John</firstname>
<lastname>Doe</lastname>
<function>manager</function>
<salary>4000.0</salary>
</person>
<person>
<firstname>Mary</firstname>
<lastname>Jones</lastname>
<function>employee</function>
</person>
<person>
I want to read them into Java Objects depending on their function: if function=manager, then a new Manager() should be created, otherwise an new Employee should be created.
Manager is a subclass of Employee. The classes look like the following:
public class Employee {
private String firstName;
private String lastName;
private String function;
// getters and setters
}
public class Manager extends Employee {
private double salary;
// getters and setter
}
I already tried using @XmlCustomizer, combination of @XmlDiscrimitatorNode and @XmlDiscriminatorValue and so on, but I can't get it to work. All examples I find are in the form where you want to map 2 subclasses that extend a 3rd one, but never when you want to map superclass and subclass together. Can somebody help me?