1

I have a simple XMLAdapter:

public class CDataXMLAdapter extends XmlAdapter<String, String> {

@Override
public String marshal(String arg0) throws Exception {
    return "<![CDATA[" + arg0 + "]]>";
}
@Override
public String unmarshal(String arg0) throws Exception {
    return arg0;
}
}

The idea behind the following code is: in my RuntimeAnnotationReader implementation I create a @XmlJavaTypeAdapter annotation at the runtime and return it in addition to my @XmlDetectCDATA annotation

public class DetectAnnotationReader implements RuntimeAnnotationReader{
...
@Override
public Annotation[] getAllMethodAnnotations(Method method, Locatable srcPos) {
    Annotation[] allMethodAnnotations = annotationReader.getAllMethodAnnotations(method, srcPos);
    if(method.getAnnotation(XmlDetectCDATA.class) != null){
        Annotation an = new  XmlJavaTypeAdapter(){

            @Override
            public Class annotationType() {
                return XmlJavaTypeAdapter.class;
            }

            @Override
            public Class type() {
                return null;
            }

            @Override
            public Class value() {
                return CDataXMLAdapter.class;
            }
        };
        allMethodAnnotations = extendAnnotationArray(allMethodAnnotations);
        allMethodAnnotations[allMethodAnnotations.length-1] = an;
    }
    return allMethodAnnotations;
}
...
}

The problem: CDataXMLAdapter adapter is not called while marshaling. Any ideas? Thanks

Goni
  • 36
  • 4

0 Answers0