Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes Can JAXB handle Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Can JAXB handle Polymorphism" Watch "Can JAXB handle Polymorphism" New topic
Author

Can JAXB handle Polymorphism

Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
Hi All,


Say I have below class structures:




Now,
say if I am trying to marshalling my java object to xml using JAXB & below code snippet :



then can JAXB handle this or does it throw any exceptions. Please suggest ?



Thanks & Regards,


RR Kumaran
SCJP 1.4
Gotur Gotur
Greenhorn

Joined: Jul 20, 2005
Posts: 4
Hi,

It doest not do the way u given the code here.one JAXB classes are generated for each "ComplexType" in ur XML Schema.One class(for Parent element in ur XML schema) will be generated which contains the instance objects for other complex elements, and each individual classes will be there for other child complex types in ur schema.
By accessing the main root element class, u can access the instances for other child elements, thats how the concepts of marshalling/unmarshalling works.
If u want to explore more, try to generate the JAXB classes for ur schema using JWSDP(Java webservices package) package using Ant Build tool.

JAXB concepts are wonderfull technoilogy in reading XML, file.

If u need more, just buzz me...here
Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
say we have a schema that resembles my class structure. I think we can represent inheritance in xml schemas.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can JAXB handle Polymorphism