cerialize
cerialize copied to clipboard
Missing in documentation: Serialization on getters / setters
This is quite angular specific, but whenever you bind a getter to angular, it looks like that if it isn't binded in autoserialize
it won't work.
Example:
@autoserialize public Quantity: number;
public set _Quantity(value: number) {
this.QuantitySpecified = true;
this.Quantity= value;
}
public get _Quantity(): number {
return this.Quantity;
}
@autoserialize public QuantitySpecified: boolean;
By binding _Quantity
to the angular's NgModel (or anything similar, really), this won't work if the instance is coming from a Deserialization.
To make it work, you need to bind the setter with serialize / deserialize / autoserialize.
So, to make it work, you need to do:
@autoserialize public Quantity: number;
@autoserialize public set _Quantity(value: number) {
this.QuantitySpecified = true;
this.Quantity= value;
}
public get _Quantity(): number {
return this.Quantity;
}
@autoserialize public QuantitySpecified: boolean;
Not really relevant with the package itself, but it's worth mentioning that it's always better to serialize the setter.