• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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 ]
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic