I have the following class hierarchy:

```
@XmlRootElement
public abstract class Animal{}

@XmlRootElement
public class Dog extends Animal{}

@XmlRootElement
public class Cat extends Animal{}

@XmlRootElement
public class Lion extends Animal{}

```

and a class which has an attribute named animal:

```
@XmlRootElement
public class Owner{
  private Animal animal;
}

```

I would like to allow different XML Schemas as follows and bind the Animal Type in the schema to `animal object` in `Owner class`

```
<Owner>
 <Dog></Dog>
</Owner>

<Owner>
 <Cat></Cat>
</Owner>

<Owner>
 <Lion></Lion>
</Owner>

```

The solutions that I have found use `XmlElements` which can take multiple `XmlElement` fields and creates a collection. However, in my case I don't need a collection but a single attribute.

Does JAXB allow any XmlElement multiple naming convention for this problem?
Is there any other annotation which could solve this problem?

Note: I have looked at multiple answers to similar questions in stackoverflow and around but almost all of them create a collection instead of a single object. The closest answer I have found is this : [@XmlElement with multiple names](https://stackoverflow.com/questions/24554789/xmlelement-with-multiple-names)

Edit : I think [this](http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html) solution might work. Have to test it out