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

Deserializing optional nested fields #88

Open
prudnikov opened this issue Sep 10, 2018 · 0 comments
Open

Deserializing optional nested fields #88

prudnikov opened this issue Sep 10, 2018 · 0 comments

Comments

@prudnikov
Copy link

Cerialize version 2.0.1

Here is example code:

    class TestNested {
      @deserializeAs(Number) id: number;
    }
    class TestModel {
      @deserializeAs(Number) id: number;
      @deserializeAs(TestNested) n: TestNested;
    }

    const data1 = {id: 1, n: {id: 2}};
    const data2 = {id: 1, n: null};
    console.log('Data1', Deserialize(data1, TestModel));
    console.log('Data2', Deserialize(data2, TestModel));

Second deserialization is failing with error while first is ok.

MyComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'id' of null
    at _Deserialize (deserialize.js:124)
    at _Deserialize (deserialize.js:139)
    at Deserialize (deserialize.js:159)
   // ... remaining stack trace

Is there any way to deserialize optional nested field? Or should I write a custom SerializeFn?

prudnikov added a commit to prudnikov/cerialize that referenced this issue Sep 13, 2018
weichx added a commit that referenced this issue Sep 14, 2018
Fixes #88: Deserializing optional nested fields
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