Move entity serialization to the model