Improved polymorphic serialization