I would move this and following lines to a method called serialization. I don't think putting all this in constuctor is the best approach.