How do I model a singleton field of a supertype of several types with
different element names?
I have these classes:
@XStreamAlias("house")
public class House {
@XStreamImplicit()
private List<Animal> animalList;
}
@XStreamInclude({Dog.class, Cat.class})
public abstract class Animal {}
@XStreamAlias("dog")
public class Dog extends Animal {}
@XStreamAlias("cat")
public class Cat extends Animal {}
so I can write:
<house>
<dog/>
<dog/>
<cat/>
</house>
and the animalList of House is filled with 2 dogs and a cat.
This works well.
Now I want to be able to do support an xml like this:
<cage>
<dog/>
</cage>
or
<cage>
<cat/>
</cage>
and a class diagram that doesn't use a List<Animal> field, but just a
field Animal:
@XStreamAlias("cage")
public class Cage {
@XStreamImplicit()
private Animal animal;
}
But that doesn't work. How can I make that work?
Without changing the XML schema.
Currently I am working around by using an List<Animal> anyway,
and adding validation that it's a singleton list... but that's undesired.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email