Improved serialization tests

(cherry picked from commit 9ac443cf9a5585d7749b184080443f51a4689438)