use of com.thoughtworks.xstream.converters.UnmarshallingContext in project workflow-cps-plugin by jenkinsci.
the class CpsThreadGroup method asXml.
@CpsVmThreadOnly
String asXml() {
XStream xs = new XStream();
// (and anyway these Describable objects would be serialized fine by XStream, just not JBoss Marshalling).
for (SingleTypedPickleFactory<?> stpf : ExtensionList.lookup(SingleTypedPickleFactory.class)) {
Class<?> factoryType = Functions.getTypeParameter(stpf.getClass(), SingleTypedPickleFactory.class, 0);
xs.registerConverter(new Converter() {
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Pickle p = stpf.writeReplace(source);
assert p != null : "failed to pickle " + source + " using " + stpf;
context.convertAnother(p);
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
// unused
throw new UnsupportedOperationException();
}
@SuppressWarnings("rawtypes")
@Override
public boolean canConvert(Class type) {
return factoryType.isAssignableFrom(type);
}
});
}
// Could also register a convertor for FlowExecutionOwner, though it seems harmless.
return xs.toXML(this);
}
Aggregations