[Validator] Fixed metadata serialization

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