users@jaxb.java.net

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

From: Jamie <jdennis_at_ipass.net>
Date: Wed, 29 Nov 2006 19:19:58 -0500

No, a static inner class wouldn't fit my needs, I don't think. I've
never used static inner classes before, so maybe I have some
misconceptions...

Levi Purvis wrote:
> Did you try a *static* inner class?
>
> On 11/28/06, Jamie wrote:
>> I was sad to see that I couldn't accomplish this with an inner class
>> (due to the inherent constructor that inner classes get). Can you
>> explain a little more what you are suggesting re: a separate class and
>> an adapter?
>>
>> Thanks!
>> -Jamie
>>
>> Kohsuke Kawaguchi wrote:
>> >
>> > Unfortunately there's no very easy way to do this. You can write a
>> > separate class and use an adapter, for example, to make it work,
>> though.
>> >
>> > 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! :)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>