Added support for custom type serialisation.