// Serialize and Deserialize
try {
Marshaller marshaller = MarshallerFactory.newMarshaller( kbase );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshall(baos, ksession);
marshaller = MarshallerFactory.newMarshaller(kbase);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
baos.close();
ksession = (StatefulKnowledgeSession)marshaller.unmarshall(bais);
bais.close();