cerialize icon indicating copy to clipboard operation
cerialize copied to clipboard

deserialize primitive number into object

Open moamenet opened this issue 4 years ago • 0 comments

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 ?

moamenet avatar Nov 18 '19 17:11 moamenet