Serialize and deserialize primitive types