diff --git a/lib/model/modelToJson.js b/lib/model/modelToJson.js index 73956459f..b87f79d83 100644 --- a/lib/model/modelToJson.js +++ b/lib/model/modelToJson.js @@ -15,7 +15,7 @@ function toJson(model, optIn) { pick: null, omitFromJson: model.$omitFromJson() || null, cloneObjects: modelClass.cloneObjectAttributes, - format: optIn && optIn.format + format: optIn && optIn.format, }; let json = toExternalJsonImpl(model, opt); diff --git a/tests/unit/model/Model.js b/tests/unit/model/Model.js index 81157682b..1ec113c49 100644 --- a/tests/unit/model/Model.js +++ b/tests/unit/model/Model.js @@ -975,6 +975,27 @@ describe('Model', () => { expect(calls).to.equal(1); }); + it('should call $formatJson with formatting options', () => { + let calls = 0; + let json = { a: 1 }; + let opt = { c: 2 }; + + Model1.prototype.$formatJson = (jsn, o) => { + ++calls; + expect(jsn).to.eql(json); + expect(o).to.eql(opt); + jsn.b = 2; + return jsn; + }; + + let model = Model1.fromJson(json); + let output = model.$toJson({ format: opt }); + + expect(output.a).to.equal(1); + expect(output.b).to.equal(2); + expect(calls).to.equal(1); + }); + it('should call $toJson for properties of class Model', () => { let Model2 = createModelClass();