cerialize
cerialize copied to clipboard
deserialize primitive number into object
I am trying to deserialize the following json:
{
"name": "test,
"price": 123
}
I am trying to deserialize it into the following classes:
export class Item {
@autoserialize name: string;
@autoserializeAs(Price) price: Price;
public static OnDeserialized(instance: Price, json: any): void {
console.log(instance.price); // <- price is here a primitive instead of the expected Price type
}
}
export class Price {
@deserialize value: number;
public static OnDeserialized(instance: Price, json: any): void {
// never gets called
instance.value = json;
}
}
The idea is, that the price class will have more functions etc, therefore I need it into the class instead of primitive. Any idea how to do that ?