added convenience methods toJson and fromJson