Skip to content

Commit

Permalink
fix(debt) Remove toJSON injection method.
Browse files Browse the repository at this point in the history
Closes: #330
  • Loading branch information
Romakita committed Apr 18, 2018
1 parent cde75cd commit 56080e7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
2 changes: 1 addition & 1 deletion src/common/converters/services/ConverterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ConverterService {
return obj.serialize(options);
}

if (typeof obj.toJSON === "function" && !obj.toJSON.$ignore) {
if (typeof obj.toJSON === "function") {
// deserialize from serialize method
return obj.toJSON();
}
Expand Down
12 changes: 0 additions & 12 deletions src/common/jsonschema/decorators/jsonProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ export function JsonProperty<T>(options?: IPropertyOptions | string): Function {
propertyMetadata.type = (options as IPropertyOptions).use as Type<any>;
}
}

return (target: any) => {
if (!target.constructor.prototype.toJSON) {

target.constructor.prototype.toJSON = function () {
return InjectorService
.invoke<ConverterService>(ConverterService)
.serialize(this);
};
target.constructor.prototype.toJSON.$ignore = true;
}
};
});
}

Expand Down
48 changes: 0 additions & 48 deletions test/units/converters/services/ConverterService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,54 +389,6 @@ describe("ConverterService", () => {
expect(this.foo.theSet[0]).to.be.an("object");
expect(this.foo.theSet[0].test).to.equals("test");
});

describe("use toJson()", () => {
before(() => {
this.fooJson = JSON.parse(JSON.stringify(this.foo2));
});
after(() => delete this.fooJSON);

it("should have an attribut with date type", () => {
expect(this.fooJson.dateStart)
.to.be.a("string")
.and.to.equals(this.foo2.dateStart.toISOString());
});

it("should have an attribut Name (because metadata said Name instead of name)", () => {
expect(this.fooJson.Name).to.be.a("string").and.to.equals("Test");
});

it("should haven't an attribut name (because metadata said Name instead of name)", () => {
expect(this.fooJson.name).to.equals(undefined);
});

it("should have an attribut with array type", () =>
expect(this.fooJson.foos).to.be.an("array")
);

it("should have an attribut with array type and an item serialized", () => {
expect(this.fooJson.foos[0]).to.be.an("object");
expect(this.fooJson.foos[0].test).to.equals("test");
});

it("should have an attribut with Map type", () => {
expect(this.fooJson.theMap).to.be.an("object");
});

it("should have an attribut with Map type and an item serialized", () => {
expect(this.fooJson.theMap.newKey).to.be.an("object");
expect(this.fooJson.theMap.newKey.test).to.equals("test");
});

it("should have an attribut with Set type", () => {
expect(this.fooJson.theSet).to.be.an("array");
});

it("should have an attribut with Set type and an item serialized", () => {
expect(this.fooJson.theSet[0]).to.be.an("object");
expect(this.fooJson.theSet[0].test).to.equals("test");
});
});
});

describe("class Foo3", () => {
Expand Down

0 comments on commit 56080e7

Please sign in to comment.