users@jaxb.java.net

Re: Jaxb unmarshalling to generic list of base class type

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 25 Mar 2010 15:23:13 +0100

You may want to study https://jaxb.dev.java.net/tutorial/index.html -
chapter 6 discusses JAXB annotations.

A good way would be to compile the Java class from an XML schema defining
your XML and copy the annotations from there. The tutorial section 2.2.13,
Defining Subtypes, shows how to write a schema similar to your case.

-W


On Thu, Mar 25, 2010 at 7:43 AM, owais zahid <owais_zahid_at_hotmail.com>wrote:

> I have an xml like this :
>
> <Zoo>
> <Lion>
> <Zebra>
> ....
> </Zoo>
>
> ----------------------------------
> And on my java <http://www.javaranch.com/> project , i have an abstract
> class "Animal" and all the animals (like lion , zebra ) extends from it.
>
> I am using JAXB , how can i unmarshal my xml to my class "Zoo" that
> contains a "List<Animal> animalList" ?
>
> public class Zoo { ..... protected List<Animal> animalList; } public class
> Lion extends Animal { ... }
>
> I hope, i explained my scenario clearly. Can someone please help me. So far
> i am unable to successfully unmarshal my xml file to List of Animals. Please
> help
>
> -Owais
> ------------------------------
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up
> now. <https://signup.live.com/signup.aspx?id=60969>
>