Handle polymorphic types when serializing/deserlializing