Refactor serialization/deserialization into class definitions - Updates #4609