Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing in documentation: Serialization on getters / setters #85

Open
briosheje opened this issue Jun 15, 2018 · 0 comments
Open

Missing in documentation: Serialization on getters / setters #85

briosheje opened this issue Jun 15, 2018 · 0 comments

Comments

@briosheje
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant