2 June 2015

Remote KIE Server, XStream and Hibernate Collections

If it is not possible or wanted to add the Hibernate-Core package to the classpath of the remote KIE Server in order to deserialize org.hibernate.collection.internal.PersistentBag and other Hibernate enchanged collections then XStream offers a solution. The xstream-hibernate project offers support to drop the internals of Hibernate enhanced collections, proxied types and Hibernate's collection proxies when marshalling such objects to XStream. All converters and the mapper have to be registered for the XStream instance:
final XStream xstream = new XStream() {
protected MapperWrapper wrapMapper(final MapperWrapper next) {
return new HibernateMapper(next);
}
};
// configure XStream for KIE!
xstream = XStreamXML.newXStreamMarshaller(xStream);
xstream.registerConverter(new HibernateProxyConverter());
xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));

Maven:
<dependency>
<groupid>com.thoughtworks.xstream</groupid>
<artifactid>xstream-hibernate</artifactid>
<version>1.4.8</version>
</dependency>