Consider following class in JavaScript:
Tools.UserBase = Tools.Class.define(\"Tools.UserBase\", Tools.EntityBase, {
UserId: { type: System.Int32, key: true,
And I've no control on serialization process at all.
Yes you do. Give you class a toJSON
method that returns an object with the expected properties and it will be recognized by JSON.stringify.
The deserialization process is the same, JSON.parse will create a plain object instead of typed objects.
Because JSON does represent plain objects, that is only natural :-) Still, you can pass a reviver function to JSON.parse, which can manipulate the returned objects and exchange them for class instances. For convenience, add a (static) fromJSON function to your class that you can use in the reviver.
Is there any JavaScript library which fits my needs?
Most MVC JavaScript libraries have built-in serialisation/deserialisation methods for their models. You can either use one of them or get inspired by their code to extend your Tools.Class
suite.