简体   繁体   中英

Is it possible to write an XmlAdapter<someType, someType>?

Namely, upon serialization in the web server I want to set to null the processDefinition field of all instances of the org.jbpm.graph.def.ProcessDefinition class, so I avoid getting this exception whenever returning values from a CXF web service

com.sun.istack.SAXException2 : A cycle is detected in the object graph. This will cause infinitely deep XML: ProcessDefinition(DailyProcess) -> ProcessDefinition(DailyProcess)

The reason for asking is that I already wrote the class below

public class XmlJbpmProcessDefinitionAdapter extends XmlAdapter<ProcessDefinition, ProcessDefinition> {

    @Override
    public ProcessDefinition unmarshal(ProcessDefinition v) throws Exception {
        return v;
    }

    @Override
    public ProcessDefinition marshal(ProcessDefinition v) throws Exception {
        v.setProcessDefinition(null);
        return v;
    }
}

defined it in the package-info.java file as

@XmlJavaTypeAdapter(value=XmlJbpmProcessDefinitionAdapter.class, type=org.jbpm.graph.def.ProcessDefinition.class)

yet its methods are never invoked.

It works fine. The problem was that my serialization was failing before getting to serialize that field so that's why my converter never got invoked.

To clarify this a bit more, this particular converter defined at package level will be invoked for all fields of the org.jbpm.graph.def.ProcessDefinition class in my own package, but not for fields of objects in say org.jbpm.graph.def package. Is this correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM