Reputation: 606
I have classes such as...
@XmlRootElement(name="Predicate")
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class Predicate implements Serializable {
}
@XmlRootElement(name="Predicates")
@XmlAccessorType(XmlAccessType.FIELD)
public class Predicates extends ArrayList<Predicate> implements Serializable {
}
Predicate happens to be a base class of a few other derived predicate types. As you can see, it's abstract. When the serialization occurs via the marshaller, it doesn't seem to create elements of the derived type, therefor on the unmarshalling i get an exception.
unable to create an instance of com.ballytech.paytable.Predicate
When extending a container class that contains a abstract base type, how am i supposed to get the inheritance to be obeyed and serialized properly. I can do this when i have class memebers that are containers which contain abstract base types, as see in examples regarding @XmlElementRef. Unfortunately this specific syntax seems incompatible.
Any help would be appreciated.
Upvotes: 1
Views: 65
Reputation: 606
Apparently the solution was to frontload the class type in the JAXBContext.newInstance(...) parameters.
JAXBContext.newInstance(BinaryPredicate.class);
Upvotes: 1