1

I have a JSON object and I need to parse it to a class instance. The JSON object can be really large, and I need to execute methods from the classes within.

I tried Object.assign and the Lodash API. The Lodash API is the best approach with the merge or mergeWith function, but I came to an impasse when the class property is an array. Even with the Lodash I have to initialize the properties from the class (Which I don't like but if I have to I'll do it).

I used this post Deep Cloning in Actionscript and this Deep clone class instance JavaScript

and nothing seems to do what I really want.

Here is the stackblitz https://stackblitz.com/edit/angular-1rva1k

I need to be able to execute methods from the classes within.

Thanks for your help.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Luislode
  • 51
  • 1
  • 7

2 Answers2

0

As @MichaelDesigaud sugested, I used the class-transformer. Sorry, I don't how to mark a comment as an answer.

Luislode
  • 51
  • 1
  • 7
-1

"I have a json object and i need to parse it to a class instance." => have you tried JSON.parse(jsonObject) ?

Leong
  • 47
  • 8