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