refact toJson and fromJson method