Fix ModelDefinition toJSON bug

When called a second time, it was supposed to return the cached json, but returned undefined instead.