users@jaxb.java.net

XmlJavaTypeAdapter annotation at package level

From: Gary Moselen <Gary.Moselen_at_orionhealth.com>
Date: Wed, 20 Sep 2006 17:52:30 +1200

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