users@jaxb.java.net

Re: XmlJavaTypeAdapter at the class level?

From: Sekhar Vajjhala <Sekhar.Vajjhala_at_Sun.COM>
Date: Wed, 22 Jun 2005 13:53:37 -0400

Dmitri Colebatch wrote:

>Hi all,
>
>I have a class that contains a list, the contents of which I'd like to
>customize the marshalling of using an XmlAdapter. Basically I have
>the following:
>
>class Accessories
>{
> List<Accessory> accessories;
>}
>
>but I'd like to change the way Accessory is marshalled. So I've tried this:
>
>@XmlJavaTypeAdapter(AccessoriesXmlAdapter.class)
>class Accessory
>{
>}
>
>but that seems to be ignored (I'm assuming that the XmlJavaTypeAdapter
>annotation is only valid on fields, but the jaxb-ri-20050407 doco
>doesn't seem to give any indication).
>
>So I'm assuming I need to write an adapter to do this:
>
>public class AccessoriesXmlAdapter extends XmlAdapter<List,List>
>
>but when I do that, I find that instead of the expected output I get this:
>
><Accessories>
></Accessories>
>
>when I step out of my custom marshall method which returns the correct
>list of 7 items that are annotated as I'd like them to be saved I find
>that in ArrayElementProperty.serializeBody(BeanT o, XMLSerializer w)
>there appears to be no TagAndType available for my mapped class and so
>the following code is executed:
>
> if(tt==null) {
> // item is not of the expected type.
> TODO.prototype(); // TODO: error report
> continue;
> }
>
>and hence I get no output.
>
>I've tried a couple of other things but without success. At this
>stage I'm going to step up a level and put a java adapter on the
>Accessories field to make it work that way until I can figure this
>out.
>
>Does the above make sense? Am I missing something? I also found that
>I got a ClassCastException when my adapter was mapping List<Accessory>
>to List<XmlAccessory> which I would have thought was correct. Sorry
>to not be more verbose on that but I did have a nice email written and
>I lost it when windows decided it had better uses for my gmail window
>(o:
>
>thanks again (in advance)
>
@XmlJavaTypeAdapter on a class is specified in the spec but not yet
implemented
by the JAXB RI. So please try with the @XmlJavaTypeAdapter on the
property/field for now.

regards
Sekhar

>
>cheers
>dim
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>