Search in sources :

Example 1 with Pickle

use of org.jenkinsci.plugins.workflow.pickles.Pickle 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);
}
Also used : Pickle(org.jenkinsci.plugins.workflow.pickles.Pickle) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) Converter(com.thoughtworks.xstream.converters.Converter) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext)

Aggregations

XStream (com.thoughtworks.xstream.XStream)1 Converter (com.thoughtworks.xstream.converters.Converter)1 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)1 UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)1 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)1 Pickle (org.jenkinsci.plugins.workflow.pickles.Pickle)1