add toJSON and fromJSON methods to entity