JAXB Polymorphism of little use

HI all.
I am finding little use in JAXB's polymorphism. As such, I think I'm going to need to switch to another framework that has a more useful polymorphism feature (or else none at all).
As indicated below, I have a schema that includes a "Person" complex type, and an "Employee" complex type that extends it. There is also an element "people" that is a sequence of "Person" elements. I have used JAXB-generated classes to add instances of Person and Employee (generated classes) to an instance of the People class. The marshaller then erroneously outputs the extensions to Person found in Employee (see below).
Having seen this, I wonder what use polymorphism (in the classes generated by JAXB) has, if it is not acceptable to use a subclass wherever its superclass is allowed. Perhaps there is some other way to do polymorphism that I'm missing?
I really want to have a functionality such as the code example below implies. Does JAXB have the feature I'm looking for, or do I need to switch to another framework? If I need to switch, which one should I use?
Thanks for any help that can be offered.
schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="people">
          <xs:annotation>
               <xs:documentation>Comment describing your root element</xs:documentation>
          </xs:annotation>
          <xs:complexType>
               <xs:sequence>
                    <xs:element name="person" type="Person" maxOccurs="unbounded"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
     <xs:complexType name="Person">
          <xs:sequence>
               <xs:element name="name" type="xs:string"/>
          </xs:sequence>
     </xs:complexType>
     <xs:complexType name="Employee">
          <xs:complexContent>
               <xs:extension base="Person">
                    <xs:sequence>
                         <xs:element name="title" type="xs:string"/>
                    </xs:sequence>
               </xs:extension>
          </xs:complexContent>
     </xs:complexType>
</xs:schema>
expected JAXB output:
<people>
<person>
<name>Joe Sample</name>
</person>
<person>
<name>Jane Sample Employee</name>
</person>
</people>
actual JAXB output (invalid):
<people>
<person>
<name>Joe Sample</name>
</person>
<person>
<name>Jane Sample Employee</name>
<title>Engineer</title>
</person>
</people>
Java code:
Person person = factory.createPerson();
person.setName("Joe Sample");
Employee employee = factory.createEmployee();
employee.setName("Jane Sample Employee");
employee.setTitle("Engineer");
People people = factory.createPeople();
people.getPerson().add(person);
people.getPerson().add(employee);
- Matt Munz

hi Matt,
I think your expected output may be wrong, and the actual output be correct eg consider this code:
import java.util.*;
class Person {
     String name;
     public String toString() { return "Person("+name+")"; } }
class Employee extends Person {
     String title;
     public String toString() { return "Employee("+name+", "+title+")"; } }
public class JBTest {
     public static void main(String[]arg) {
          List l = new ArrayList();
          Person p = new Person();
          p.name="Joe Sample";
          Employee q = new Employee();
          q.name="Jane Sample Employee";
          q.title="Engineer";
          l.add(p);
          l.add(q);
          System.out.println(l);
which outputs
     [Person(Joe Sample), Employee(Jane Sample Employee, Engineer)]
So although the List is untyped (am not keeping up with generics..
sorry!) in the above code, even if it were a Person list it would still be legitimate to add an Employee to the list (since an Employee is-a
Person)
saying that, am not sure how you could achieve what you are trying? are you hoping for the object tree you construct not to be validated?
thanks,
asjf

Similar Messages

  • My iPhone 5 with 6.1.2 is draining the battery in 4 hours with little use. It has just started. Any suggestions.

    My iPhone 5 with 6.1.2 is draining the battery in 4 hours with little use. It has just started. Any suggestions? Any apps that are known to cause a problem? I recently loaded Fantastical and Cobook (since deleted).

    hello if you dubble tap the home button and see if thare are app if so delete the. if your still haveing problem then turn the britness down. and if that duse not work you must have gottin a defective battery

  • I just bought my phone few days ago. From the day I bought it I realized the phone heats up after a little use. It gets really hot while using Wifi and downloading. Anyone else having these issues? What's the solution to this?

    From the day I bought it I realized the phone heats up after a little use. It gets really hot while using Wifi and downloading. Anyone else having these issues? What's the solution to this?

    Your VGA is definitely corrupted and it is irreparable, so just make the HP to change your vga.
    Also next time read my post on how to keep your laptop cool to avoid same issues again.
    I assume your laptop was pretty hot during some time and that's the result you've got.
    Make it easier for other people to find solutions, by marking my answer with 'Accept as Solution', if it solves your problem.
    Click on the BLUE KUDOS button on the left to say "Thanks"

  • JAXB polymorphism

    Hi,
    I am using jaxb 1.0.4 and my shemas are as follows.,.
    document.xsd
    <xs:schema>
         <xs:element name="document" type="documentType"/>
         <xs:complexType name="documentType">
              <xs:sequence>
                   <xs:element name="instance" type="xs:string"/>
                   <xs:element name="version" type="xs:string"/>
                   <xs:element name="event" type="EventType"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="EventType" abstract="true">
              <xs:sequence>
                   <xs:element name="event_type" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>
    <xs:schema>
         <xs:complexType name="AmendmentEventType">
              <xs:complexContent>
                   <xs:extension base="EventType">
                        <xs:sequence>
                             <xs:element name="amendedBy" type="xs:string"/>
                             <xs:element name="book" type="BookType"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:element name="amendmentEvent" type="AmendmentEventType"/>
    </xs:schema>
    In my java class I want to use something like this..
              Document document = objFactory.createDocument();
              AmendmentEventType amendmentEvent = objFactory.createAmendmentEventType();
              //set the fields in AmendmentEventType
              document.setEvent(amendmentEvent);
    When I marshall the document object I get the following exception.
    Location: obj: DocumentImpl@406199
    com.sun.xml.bind.serializer.AbortSerializationException: tag name "AmendmentEventType" is not allowed. Pos
    sible tag names are: <EventType>
    Is this polymorphism not allowed in Jaxb?

    hi Matt,
    I think your expected output may be wrong, and the actual output be correct eg consider this code:
    import java.util.*;
    class Person {
         String name;
         public String toString() { return "Person("+name+")"; } }
    class Employee extends Person {
         String title;
         public String toString() { return "Employee("+name+", "+title+")"; } }
    public class JBTest {
         public static void main(String[]arg) {
              List l = new ArrayList();
              Person p = new Person();
              p.name="Joe Sample";
              Employee q = new Employee();
              q.name="Jane Sample Employee";
              q.title="Engineer";
              l.add(p);
              l.add(q);
              System.out.println(l);
    which outputs
         [Person(Joe Sample), Employee(Jane Sample Employee, Engineer)]
    So although the List is untyped (am not keeping up with generics..
    sorry!) in the above code, even if it were a Person list it would still be legitimate to add an Employee to the list (since an Employee is-a
    Person)
    saying that, am not sure how you could achieve what you are trying? are you hoping for the object tree you construct not to be validated?
    thanks,
    asjf

  • HT4623 Hi, I do have the first iPad, however had little use of it. I had extended guarranty that ended end of 2012

    Hi, I bought the first iPad, complete, with extended guaranty and internet connection.
    Services ended in october 2010. Actually I never used the iPad or internet connection.
    Had a health treatment ( I used to forget what i did few minutes before) today I am
    better , not completly, but much better. I am very upset I could not use services I bought
    or iPad, actually Apple can check I did not use iPad at all for two years.
    Question, how I can get some chance from Apple, and at least have my free internet connection(one year)
    back, that I supose to enjoy during 1 year after purchase and I never did.
    Also, now there are new iPads, but I can not afford to buy the new ones today until I get completly recover
    and get back to work. What is the difference between the first iPad and the new ones. The only thing I understand
    is less is that the old one does not take pictures. Still I really would like to know if I can use this old model normally
    and what I do not have in old one that new ones have.
    Does Apple Store in Chicago where I got my first iPad change it for new iPad paying a little difference to enjoy
    using it, as I never had opportunity to use my first one.
    Looking forward for your kind return
    Tzu

    The iPad 1 has no camera, a slow processor and low amount of RAM. The iPad 1 can only operate on iOS 5.1.1, whereas, the iPad 2 to current iPads can run iOS 7.x. The newer iPads have faster processors, more RAM and a better display.
    Your 1 yer internet opportunity has long ago expired.
    Your only option is to sell the iPad and buy a new one.  Apple does not take tradeins.
    Apple Reuse and Recycle Program
    http://store.apple.com/us/browse/reuse_and_recycle
    How to Sell Your Old iPad  http://tinyurl.com/85d69lk
    Other sources to sell.
    eBay Instant Sell http://instantsale.ebay.com/?search=ipad
    Sell and Recycle Used Electronics - Gazelle http://www.gazelle.com/
    For instant gratification in selling a used iPhone or iPad, Gazelle’s Gadget Trader, an iOS app, is tough to beat. In seconds it detects the device and reveals how much it is worth in good condition. Tap the Sell This Phone to Gazelle button and the deed is done.
    Sell Electronics for Cash - Next Worth  http://www.nextworth.com/
    Buy My Tronics  http://www.buymytronics.com/
    Sell Your iPad http://www.sellyourmac.com/mac-product-guides/ipad.html
    Totem http://www.hellototem.com/
    What to do before selling or giving away your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/HT5661
     Cheers, Tom

  • HT2693 The Icloud acount has little use but saying its almost full

    Dear Sir/Madam,
    I have this Icloud acount and very happy with it.
    I also have some Apple Devices such as Ipad, Iphones etc. From those devices I have checked that I had used less than 1G in usage. but it shows that my account is almost full. I have contacted some of your App Stores in Sydney. All they do not know why and refere me to contact with you directly.
    Please let me know what is happening to my account.
    Looking forward to hearing from you soon.

    Basic troubleshooting steps outline in the manual are restart, reset, restore from backup, restore as new.  Try each of these in order until the problem is resolved.  If you've been through all these steps and the trouble persists, you'll need to bring your phone to Apple for evaluation.  Be sure to make an appointment first at the Genius Bar so you won't have a long wait.
    Best
    GDG

  • Apple Care of little use to me

    I tried to use this service for the first time some time ago - having two licenses, imac and macbook - but I have neither time nor patience to wait for contact on the phone for forever. I sent a complaint via e-mail to Apple, but have heared nothing from those guyes. So far this product has been a vaste of money.
    Message was edited by: Vossing

    Vossing,
    One thing you didn't make clear, was, were you expecting a callback from Apple after a certain amount of time, or were you on hold for a specific amount of time? Perception of "forever" varies by person, and what is one person's grueling torture, is a walk in the park for another. I'm not trying to be insensitive, but exactly what were you calling about, and which way did the feedback fail? The e-mail form says not to expect a response if you read it carefully regarding iMacs. So naturally it appears you weren't addressing the right place. While I agree, long hold times don't give a proper appearance, knowing what exactly happened will strengthen your argument.
    I'd give them another try, assuming you were able to hear the hours that they were open, and this time, document exactly when you start waiting, and what was your response.
    Message was edited by: a brody

  • After Software Updates Applied Mac Mini Freezes after little use

    Yesterday I let the computer run updates, now after a short period of use the computer desktop goes to an hour glass and I have to reboot to get control back. Even terminal sessions are frozen. Only Apple software installed on the computer, except for PostgreSQL, Sonos and Mozy. I deinstalled Mozy but that did not help.
    Thanks for any help you can provide.

    BVR wrote:
    I wonder if its a virus?
    whatever it is that plagues your machine, i certainly isn't a virus - there aren't any for Mac !
    however, i'm running out of options. the only other thing i can think of would be a complete re-installation of Mac OS. if that doesn't fix your mini, and if it's still under warranty, i would start planing a trip to Apple.
    before embarking on that path, be sure you're well baked up. if you don't have a spare, get an external HD (USB or, better yet, firewire) and use e.g. Carbon Copy Cloner to bootably clone your startup disk. a current TM backup would also do (but i recommend both).
    maybe another user has a better idea. best of luck in any case !
    JGG

  • My iPod touch will not shuffle or move on to the next song on an album/ playlist. Is there anything I can do. It has had very little use even though I've had it for 2years.

    Can anyone help with an iPod touch that will not shuffle or move on to the next song on an album/playlist?

    After you dry the iPod:
    How to fix a wet iPod or iPhone | eHow.comfix-wet-ipod-iphone.html
    Connect the iPod to a charging source overnight and then try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try on another computer
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar       
    If iTunses can see the iPod you can backup the iPod
    iOS: How to back up
    http://support.apple.com/kb/HT1766and copy media from the iPod
    Recovering your iTunes library from your iPod or iOS device: Apple Support Communities
    If iTunes does not see the iPod then its contents are lost

  • How can I archive little used contacts and then reuse?

    I have about 400 or so contacts in Address Book, some of them I want to keep but as they are related to old projects I've worked on I don't want them in my active Address Book (which syncs to my phone).
    What is the best way/what are the alternative ways of doing this?
    Ideally I want my 'live contacts' in address Book and Phone but my other contacts saved somewhere easily accessible as sometimes I will need to pull them into my 'live contacts again for a while.
    Solutions much appreciated
    (I'm running Tiger on my iMac and Leopard on my PG, currently if that makes any difference}

    do an archive, file>export>address book archive, and archive that Ab with a specific name, then when you need that archive, you can archive the "live contacts" with another archive name, and then import that first archive and so on and so forth...
    hope this helps

  • Update Unbounded element using SOAP_CLIENT and JAXB classes

    I am writing a custom worklist application using 10.1.3.3. I am able to successfully kick off my BPEL process from my Java application and I am even able to modify most of the fields defined in my XSD. My problem occurs when I try to update the unbounded elements. They are of complex type and each request can have an unlimited number of these elements.
    I used JDeveloper's tool to generate the JAXB classes I'm using to interact and modify the payload of my task. I know that JAXB does not generate setter methods for unbounded elements. I should be able to get the list of elements and simply add to it. Unfortunately, the new list elements are not being saved when I marshall my payload and update the task with the new payload.
    Any ideas on what I'm doing wrong or if there is another way to do this? I've posted code snippets below.
    Thanks!
    Quote Element from XSD:
    <xsd:element name="Quote" nillable="true" minOccurs="0" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="WorksheetId" type="xsd:int" minOccurs="0"/>
    <xsd:element name="QuoteId" type="xsd:int" minOccurs="0"/>
    <xsd:element name="Description" nillable="true" minOccurs="0">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:maxLength value="250"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="Quantity" type="xsd:int" nillable="true" minOccurs="0"/>
    <xsd:element name="UnitPrice" type="xsd:float" nillable="true" minOccurs="0"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    AddQuote java code:
    JAXBContext jc = JAXBContext.newInstance("myproject.xml");
    Unmarshaller u = jc.createUnmarshaller();
    Task detailTask = wfSvcClient.getTaskQueryService().getTaskDetailsById(ctx, thisId);
    Element detailPayload = detailTask.getPayloadAsElement();
    ObjectFactory objFactory = new ObjectFactory();
    XMLWorksheet xRequest = objFactory.createWorksheet();
    xRequest = (XMLWorksheet)u.unmarshal(detailPayload.getFirstChild());
    List quotes = xRequest.getQuote();
    quotes.add(quote);
    Marshaller m = jc.createMarshaller();
    m.marshal(xRequest, detailPayload);
    detailTask.setPayloadAsElement(detailPayload);
    taskService.updateTask(ctx, detailTask);

    who actually managed to make the SOAP_CLIENT working ?
    What is the jar list and order you use ?
    Does it work with java 5 ?
    Thanks for the help!

  • Is there a way to add event details using a calendar object vs. those dumb field entry boxes?

    I have switched from PC to Mac over a year and a half ago, and have been plagued with the "dumb" date entry boxes in iCal and now Reminders on the mac. For one, they don't show you the DAY OF WEEK for an event, it assumes you are parked on that day, but of course reality sets in and causes constant date changes for events. Picking a date in the future would be much more helpful if Apple followed some usability norms in iCal. For instance, if you are booking a flight online, those helpful little calendar objects pop up, and further, they are smart about "end dates and times" for events, knowing it can't be earlier than the start date. Apple iCal unfortunately always thinks you are creating an ALL DAY event, and when you change the start time, it creates the end time for the next day. Not very smart. Or is it me that is not very smart for constantly hawking every little data entry field for correctness. Why, oh why dear lord has Apple not given some usability attention to iCal on the mac??? At least match the interface of the iPhone with a nice little slot machine rolling control.
    Is there an add in?
    Is there hope that Apple will ever fix its lagging Mail and iCal apps on the Mac?
    Please advise. Or just offer a kind word of consolation if there is no hope for a better interface.

    In the future, Swing related questions should be posted in the Swing forum.
    The code you posted is of little use since it uses custom classes so we can't see the behaviour of your code.
    In general if you add a component to a Container at run time then you just use
    container.revalidate()
    This will invoke the LayoutManager and repaint the components in the container based on the new layout.

  • How can I use or convert a imaq image to plot images back on waveform graph

    Hi
    I am currently opening and manipulating (rotate and resize) a PNG image using IMAQ Vision in LabView 8.2.1 This works well and I can display the Image on the front panel using a IMAQ Image Control.
    In addition to this I would now like to display the image as a background on waveformgraph. I can do this with the original PNG file by reading it and then flatten it to a pixmap ie make it a Picture but this is of little use as I need to use the manipulated IMAQ image.
    Therefor I would like to know how to convert the manipulted IMAQ Image to right Picture Format (without resaving) in order to use it on the PlotImages.Back property node of a wavefrom graph.
    I very much welcome your suggestions as I feel it should be easy yet can not seem to solve it. Thank you for your time!!!

    Hi Randall
    Apologies for replying somewhat late but I have been out of the office for a few days.
    Your suggestions and code helped me greatly and led to solving my query so thank you for that.
    There is one more thing (well many many more but I will place new posts for those  however that you might be able to answer for me.
    Following your suggestion to use the image to array function I searched through more examples and found the code that did exactly what I wanted to do. Please see attached.
    In this code a For loop is used to add 65793 to the color table. It works very well but I do not know why it is used exactly. Can you exlplain? I also realize I never made it clear that I use grayscale PNG files rather then color images.
    Thanks again for your excellent help, it is much appreciated.
    Attachments:
    IMAQ_8-bit_to_picture v1.vi ‏15 KB
    Test Image.png ‏42 KB

  • How to use a substitution variable in a load rule?

    I need to use a substitution variable in a load rule in a column, as I will receive a parameter to fix the Month and Year values within the data loading, could somebody tell me if this is possible. I put an expresion "&Yearproc" in the column value but it is not working.

    If you're a member of ODTUG (or even if not, you can sign up for an associate membership for free) you can download Glenn's presentation from 2009 Kaliedoscope "Little Used Features of Essbase (Like Data Mining and Triggers)" -- there is a section in that presentation on substitution variables -- he does a really good job in showing how this works.
    Go to: www.odtug.com, then Tech Resources, then Essbase/Hyperion, and search for Schwartzberg. Currently it's the ninth presentation on the list -- I think this changes based on popularity of downloads.
    Regards,
    Cameron Lackpour

  • How to use a presentation variable in filter conditions

    Hi,
    I have set a presentation variable "day" on my dashboard prompt containing a date column. I now need to use this presentation variable in the filter clause to restrict the dates between "day" and sysdate.
    So i apply the following SQL filter:
    where day between '{@variables.day}' and current_date
    But I end up in getting the following error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1861, message: ORA-01861: literal does not match format string at OCI call OCIStmtExecute. [nQSError: 17011] SQL statement execution failed. (HY000)
    I even tried casting the presentation variable to date, but to no avail. Can someone let me know how to specify the date format for the presentation variable.

    If you're a member of ODTUG (or even if not, you can sign up for an associate membership for free) you can download Glenn's presentation from 2009 Kaliedoscope "Little Used Features of Essbase (Like Data Mining and Triggers)" -- there is a section in that presentation on substitution variables -- he does a really good job in showing how this works.
    Go to: www.odtug.com, then Tech Resources, then Essbase/Hyperion, and search for Schwartzberg. Currently it's the ninth presentation on the list -- I think this changes based on popularity of downloads.
    Regards,
    Cameron Lackpour

Maybe you are looking for

  • Buttons not showing up for Writeback option in OBIEE 11g

    Hey guys, I'm struggling with the writeback option in OBIEE 11g. I've made all the required changes as per the documentation. 1) Making the column writeable in BMM layer. 2) Giving the column and the table read/write permission in the presentation la

  • Why the app tab does desappear from my Ipod touch 4?

    Can someone tell me why is desappear the app tab from my Ipod touch 4?  How can I do to see it again?  I need it to download app on my Ipod. Thanks

  • Unable to install Elements 13.

    Unable to install Elements 13

  • Personal hotspot not working ios8.2

    HI in response to a suggestion here to cure another issue (constant "Cannot download Item" messages), I recently reset the Network Settings on my iPhone 4S. Since then I have been unable to get the personal hotspot to work reliably. My carrier (3) wa

  • Will ipod 5G video 80Gb work with B

    Hi,     Just trying to clear this problem up, I have the Bowers & Wilkins Zeppelin Air Dock and recently purchased an 80 Gb ipod 5G Video (circa 2006), I purchased this 2nd hand recently from e-bay and it sounds superb through headphones and enables