users@jaxb.java.net

Re: XmlJavaTypeAdapter annotation at package level

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 21 Sep 2006 10:33:35 -0700

That's simply because by default, a private property is not subject to
the binding. Put @XmlElement on it and you should see the package-level
adapter kick in.

Gary Moselen wrote:
> Hello,
>
> I'm having trouble getting may package annotated @XmlJavaTypeAdapter to kick in:
>
> com.Foo.java>>>
>
> package com;
>
> import javax.xml.bind.JAXBContext;
> import javax.xml.bind.Marshaller;
> import javax.xml.bind.annotation.XmlRootElement;
>
> import org.joda.time.DateTime;
>
> @XmlRootElement
> public class Foo {
>
> private DateTime now = new DateTime();
>
> public static void main(String[] args) throws Exception {
>
> final JAXBContext jc = JAXBContext.newInstance("com");
> Marshaller m = jc.createMarshaller();
> m.marshal( new Foo(), System.out);
> }
> }
>
> <<<
>
> com.package-info.java>>>
>
> @XmlJavaTypeAdapters(@XmlJavaTypeAdapter( type = DateTime.class, value = DateTimeAdapter.class))
> package com;
>
> import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
> import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
>
> import org.joda.time.DateTime;
>
> import com.orchestral.orders.jaxb.adapters.DateTimeAdapter;
>
> <<<
>
> But my output is just:
>
> <foo/>
>
> If I add the annotation explicitly on the attribute (in Foo.java):
>
> @XmlJavaTypeAdapter( DateTimeAdapter.class)
> private DateTime now = new DateTime();
>
> Then the ouput is as expected:
>
> <foo><now>200609201741</now></foo>
>
>
> Why isn't the package annotation working?
>
> thanks,
> Gary
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com