Object (de)serialisation: class loaders

Following up my previous post on object serlialisation and deserialisation, a minor gotcha: Passing ‘null’ as the second parameter to JavaSerializer may throw ClassNotFoundException when reading your own custom classes back in.

So, pass to JavaSerializer a class loader you know can load your custom classes. For me, the easiest to use is the class loader which has already created one of my own objects, like so:

val js = new JavaSerializer(null, classOf[com.sdstrowes.simulator.RIB].getClassLoader())

The rest remains the same.


Posted by Stephen Strowes on Thursday, September 24th, 2009. You can follow me on twitter.

Recent Posts

(full archive)

All content, including images, © Stephen D. Strowes, 2000–2016. Hosted by Digital Ocean.