shakilsiraj / json-object-mapper

A TypeScript library to serialize and deserialize object graph from/to JSON in a fast and non-recursive way
MIT License
58 stars 18 forks source link

Deserialization not working on typescript 3.1.1 #50

Open jonghshin opened 3 years ago

jonghshin commented 3 years ago

Hello,

Deserialization does not work on typescript 3.1.1 and/or Angular 10. I copied, pasted and ran the SimpleRoster deserialization example on typescript 3.1.1 and/or Angular 10, but that example does not work. I created stackblitz.

https://stackblitz.com/edit/angular-ivy-ftq9ct?file=src%2Fapp%2Fapp.component.ts

jonghshin commented 3 years ago

I just found out that only the properties that have initial values are being deserialized. It looks like line 243 in ObjectMapper.js is the problem. Object.keys only returns properties that have values.

nicko466 commented 3 years ago

Hi Jonghshin,

as describe in the README, you should initialize your properties to undefined. It fixes the deserialization. Your stackblitz with the fix https://stackblitz.com/edit/angular-ivy-pknkua?file=src%2Fapp%2Fapp.component.ts