Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can JAXB handle Polymorphism

 
Rr Kumaran
Ranch Hand
Posts: 548
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Gotur Gotur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 548
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
say we have a schema that resembles my class structure. I think we can represent inheritance in xml schemas.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic