Refactor serialization api