• 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:

Polymorphism in JAXB2

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does JAXB 2 understand inheritance? I have a class Student which have two derived class HostelStudent and DayStudent. One property is different between 2 derived class i.e roomNo (HostelStudent) and lockerNo(DayStudent).

xml structure for unmarshall is

<blockquote><font size="1" face="Verdana, Arial">code:</font><hr><pre name="code" class="core"><font size="2">

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Student>
<rollNo>0</rollNo>
<name>Darren</name>
<className>V</className>
<englishMarks>90</englishMarks>
<roomNo>121</roomNo>
</Student>

</font></pre><hr></blockquote>

I want when input xml will have element < lockerNo> then JAXB should create object DayStudent and when there is <roomNo> it should create object of HostelStudent.
Or can we make one field a descriptor field? Like if rollNo (which is in basse class) is 0 then object will be HostelStudent else DayStudent.

I cannot change the xsd or input xml structure
Thanks in advance.
[ July 24, 2008: Message edited by: Sandeep Ghosh ]
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic