Let's suppose I have a json:
{"firstName": "Mike", "age": 35}
And a class:
export class Person {
private firstName: StringProperty = new SimpleStringProperty();
private age: IntegerProperty = new SimpleIntegerProperty();
public constructor() {
//does nothing
}
public setFirstName(firstName: string): void {
this.firstName.set(firstName);
}
public getFirstName(): string {
return this.firstName.get();
}
public setAge(age: number): void {
this.age.set(age);
}
public getAge(): number {
return this.age.get();
}
}
Can I make class-transformer use getters/setters when converting to/from json?
Well you can do it basically using
Object.assign
but you need to use actual getters and setter like below :Edit: This might be dangerous if source jsons properties differ from the target class. That might add some additional properties to the instance which is not visible to type system. So you may want to use
Object.seal
method. Playground Link