Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

giving to @XmlJavaTypeAdapter a generic type value

843834Apr 30 2009 — edited May 5 2009
Hi all
I have a critical problem with adapters used at jaxb unmarshall

some of my fields have type enumeration. I decided that is best to use same adapter class for all enums so i created a generic enumeration adapter. I'm not sure if is 100% ok but here it is:


EnumerationAdapter.java :
public class EnumerationAdapter<T extends Enum<T> > extends XmlAdapter<String, Enum<?>> {
 
    private Class<T> _enumClass;
    /*
     * (non-Javadoc)
     * 
     * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
     */
    @Override
    public String marshal(Enum<?> e) throws Exception {
        return e.toString();
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
     */
    @Override
    public Enum<?> unmarshal(String v) throws Exception {
        // TODO Auto-generated method stub
        return T.valueOf(_enumClass, value);
    }
}
The adapter is called at unmarshall but i can't set type T as i want.
The problem is how i declare @XmlJavaTypeAdapter annotation that.
It should be something like this.
@XmlJavaTypeAdapter(EnumerationAdapter<MyEnum>.class)
protected MyEnum field;
Of course syntactically is wrong, but i don't know how to declare it correctly. I.m not sure if at least this is possible.
Also i've noticed that i have to give explicit types to annotations ( not like xxx.getClass() ) :(

So I'm in deep d***, please do try to help me.
Thanks all.
Best regards
Marian
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2009
Added on Apr 30 2009
7 comments
1,770 views