users@jaxb.java.net

Re: XmlJavaTypeAdapter annotation at package level

From: Gary Moselen <gary.moselen_at_orionhealth.com>
Date: Mon, 25 Sep 2006 11:07:19 +1200

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
>>
>>
>>
>>
>
>
>
>