• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can JAXB handle Polymorphism

 
Ranch Hand
Posts: 548
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
say we have a schema that resembles my class structure. I think we can represent inheritance in xml schemas.
 
Hang a left on main. Then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic