Add condition in serialize polymorphic method