https://github.com/blixt/js-objectmanager
A JavaScript library that handles serialization and deserialization of objects, preserving reference integrity. Ideal for storing a complex data structure as JSON.
https://github.com/blixt/js-objectmanager
Last synced: 5 months ago
JSON representation
A JavaScript library that handles serialization and deserialization of objects, preserving reference integrity. Ideal for storing a complex data structure as JSON.
- Host: GitHub
- URL: https://github.com/blixt/js-objectmanager
- Owner: blixt
- Created: 2010-04-21T16:09:33.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2010-04-21T16:09:51.000Z (about 16 years ago)
- Last Synced: 2025-10-11T15:58:39.866Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Object manager
## Information
A JavaScript library that handles serialization and deserialization of objects,
preserving reference integrity. Ideal for storing a complex data structure as
JSON.
## Example
var a = {aString: 'hello', aNumber: 12.3, aBool: true,
anArray: [1, 2, [3, 4]], anObject: {anotherObject: {
hello: 'world', iAm: 1337}}},
b = {referenceToArray: a.anArray, referenceToA: a,
referenceToSubObject: a.anObject.anotherObject,
anotherString: 'weeee'},
c = {references: [a, b]},
d = [a, b, c];
// Create an ObjectManager instance and register variables a, b, c and
// d.
var manager = new ObjectManager();
manager.register(a, 'a');
manager.register(b, 'b');
manager.register(c, 'c');
manager.register(d, 'd');
// Serialize and deserialize the registered objects.
var serialized = manager.serialize();
var deserialized = ObjectManager.deserialize(serialized);
// (Support for the console object required)
// Shows the instances before and after serialization as well as the
// serialized version of the data.
console.log({
before: [a, b, c, d],
intermediate: serialized,
after: [deserialized.get('a'), deserialized.get('b'),
deserialized.get('c'), deserialized.get('d')]
});
The above example is probably not a practical use case. In a real project, you
would probably convert the result of `manager.serialize()` to JSON, store it
somewhere, then later retrieve it and parse it, and call
`ObjectManager.deserialize(...)` with the resulting object.
## MIT license
This project is licensed under an MIT license.
Copyright (c) 2009-2010 Andreas Blixt