wrapped serialization code into factory