Refactored polymorphic serialization