Search in sources :

Example 21 with UnmarshallingContext

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);
}
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

UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)21 Test (org.junit.Test)20 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)19 TreeUnmarshaller (com.thoughtworks.xstream.core.TreeUnmarshaller)16 StringReader (java.io.StringReader)12 InputStream (java.io.InputStream)10 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)8 XppReader (com.thoughtworks.xstream.io.xml.XppReader)8 HashMap (java.util.HashMap)8 InputTransformer (ddf.catalog.transform.InputTransformer)6 Map (java.util.Map)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 XStream (com.thoughtworks.xstream.XStream)3 DomReader (com.thoughtworks.xstream.io.xml.DomReader)2 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)2 Metacard (ddf.catalog.data.Metacard)2 InputStreamReader (java.io.InputStreamReader)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2