AngularJs 1.x
Imal Perera  

Does Angular needs Something Like GSON ?

Spread the love

JavaScript developers tend to use Literal notation of Objects rather than Classes (Prototype or Constructor according to ECMAScript 5) that is fine as long as you are sure that your project is small and bit of things to do in client side, but when we are talking about fully single page applications that means thousands of thousands of code reside in client side and at that time the importance of  types and basic OOP concepts are very vital unless very easily you will loose control over your own project but javascript is does not have them at the moment, so if you are not using TS and you are working on a big project the main important thing is to layout your classes properly.

This article is about a problem and my own solution to which developers face when using the above way, Specially when dealing with REST apis. Main problem when you work with REST apis is that how do you convert your literal notion object created after consuming REST api to a instance of a Class, JavaScript does not have something similar to googles GSON (or Jackson) which used very much in java space to serialize JSONS and vice versa. so developers will have to manually generate the object tree, this may be very painful and you have to do it again in the next project.

I recently created a project to address this problem with angular 1.0 and it allows you to convert json to Javascript Class instances and Instances to jsons, currently version 1.0 but hopefully this will get contribution.

Try out  Angular-JSClass 

Leave A Comment