Klaus Posted April 20, 2015 Share Posted April 20, 2015 Hey there, I've done quite some research, but I'm not totally satisfied with what I found. Just to be sure here's my question: What is actually the most robust and elegant automated solution for deserializing JSON to TypeScript runtime class instances?Say I got this class:class Foo { name: string; GetName(): string { return this.name };}And say I got this JSON string for deserialization:{"name": "John Doe"}What's the best and most maintainable solution for getting an instance of a Foo class with the name set to "John Doe" and the method GetName() to work? I'm asking very specifically because I know it's easy to deserialize to a pure data-object. I'm wondering if it's possible to get a class instance with working methods, without having to do any manual parsing or any manual data copying. If a fully automated solution isn't possible, what's the next best solution? Thanks and cheers. Link to comment Share on other sites More sharing options...
Klaus Posted April 29, 2015 Author Share Posted April 29, 2015 Quick update in case anybody stumbles upon this thread. I found a solution to my problem. Basically, the following StackOverflow threads helped me achieve my goal: http://stackoverflow.com/questions/22885995/how-do-i-initialize-a-typescript-object-with-a-json-objecthttp://stackoverflow.com/questions/29758765/json-to-typescript-class-instance (This one is created by me and holds the same question as this thread) Cheers Link to comment Share on other sites More sharing options...
Recommended Posts