I found the solution after some further research...
XStream allow to intercept the (un-)marshalling processes by adding converter. Hence I registered the following converter which stop (un-)marshalling as soon as a FirefoxDriver class is identified.
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
public class CutoffConverter implements Converter{
@SuppressWarnings("unchecked")
public boolean canConvert(Class type) {
return type.equals(FirefoxDriver.class);
}
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
}
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
return null;
}
}
Registering it at the XStream instance is simple:
XStream xstream = new XStream();
xstream.registerConverter(new CutoffConverter());
Maybe someone finds this helpful.