users@jaxb.java.net

Re: XmlJavaTypeAdapter annotation at package level

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 25 Sep 2006 15:40:23 -0700

Must be a bug then. Would it be possible to file this as an issue to
http://jaxb.dev.java.net/issues/ ?

Gary Moselen wrote:
> Hi,
>
> Thanks for correcting me; if I fix this in my test case I still do not get as I expect.
>
> @XmlElement
> public DateTime now = new DateTime();
>
> Then the result is:
>
> <foo><now/></foo>
>
> but with an explicit @XmlJavaTypeAdapter annotation on the filed I get as expected.
>
> <foo><now>200609221046</now></foo>
>
> I have tried getter/setter access with similar results.
>
> thanks
>
>
> Kohsuke Kawaguchi wrote:
>
>>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
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>------------------------------------------------------------------------
>>
>>Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------ms010604060601090406090508"
>>
>>--------------ms010604060601090406090508
>>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>Content-Transfer-Encoding: 7bit
>>
>>
>>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
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> 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