Fix serialization of tagged types