A Typescript json (de)serializer
npm install jerialize#Jerialize
Nodejs:
> npm install jerialize --save
Systemjs:
> jspm install npm:jerialize
import * as jerialize from "jerialize";
class MyClass{ @jerialize.serialize()
public simpleProperty: string;
@jerialize.serialize()
public simpleArray: Array;
@jerialize.serialize({type: AnotherClass}) //Providing the type is required
public objectProperty: AnotherClass;
@jerialize.serialize({type: AnotherClass}) //Providing the type is required, arrays are autodetected
public objectArray: Array;
constructor(){ // The constructor has to be without parameters or each parameter has to be optional
...
}
}
var jerializer.Serializer = new jerializer.Serializer();
var testObj: MyClass = new MyClass();
//fill the fields of testObj
var serialized: string = serializer.serialize(testObj,true);
var deserialized: MyClass = serializer.deserialize(MyClass,serialized);
``