Serialization for custom classes