[Validator] Fixed metadata serialization

This is the sister PR for #8402 for the 2.1 branch.