users@jaxb.java.net

Re: dealing with an element that isn't in your java objects?

From: Levi Purvis <javanet_at_purvis.ws>
Date: Wed, 22 Nov 2006 14:50:11 -0500

I wanted to do the same thing, but couldn't find a clean way to do it.
 You might have to create a class to represent the ExternalLooks
element. I've filed an enhancement request for something like this,
but for only wrapping a single element. Would you mind adding your
example to this issue -- ?

https://jaxb.dev.java.net/issues/show_bug.cgi?id=272


On 11/22/06, Jamie wrote:
> I have a problem I'm trying to solve where there is an element that some
> of my object's attributes belong to but others don't in the XML, but
> none of them do (the element does not exist) in my java object.
>
> Given the following POJO class:
>
> class Car {
>
> int getNumberOfDoors() {
> return 4;
> }
>
> String getColor() {
> return "blue";
> }
>
> boolean isConvertable() {
> return false;
> }
>
> boolean isLeftHandDrive() {
> return false;
> }
>
> }
>
> I need to marshal out the following XML:
>
>
> <Car>
> <NumberOfDoors>4</NumberOfDoors>
> <ExternalLooks>
> <Color>blue</Color>
> <Convertable>false</Convertable>
> </ExternalLooks>
> <LeftHandDrive>false</LeftHandDrive>
> </Car>
>
> If you notice, the ExternalLooks element does not exist in my object,
> but is specified in the schema. I'm basically looking for good ways to
> solve this, i.e. make my XML from my current object marshal out
> compliant with this schema.
>
> I'd love to hear ideas, especially if there is a "right" way to do this
> with JAXB! :)
>
> Thanks!
> -Jamie