1 |
Class("Joose.Storage.Unpacker", { |
2 |
classMethods: { |
3 |
unpack: function (data) { |
4 |
var name = data.__CLASS__; |
5 |
if(!name) { |
6 |
throw("Serialized data needs to include a __CLASS__ attribute.") |
7 |
} |
8 |
var jsName = this.packedClassNameToJSClassName(name) |
9 |
|
10 |
var co = this.meta.classNameToClassObject(jsName); |
11 |
|
12 |
return co.unpack(data) |
13 |
}, |
14 |
|
15 |
// Format My::Class::Name-0.01 We ignore the version |
16 |
packedClassNameToJSClassName: function (packed) { |
17 |
var parts = packed.split("-"); |
18 |
parts = parts[0].split("::"); |
19 |
return parts.join("."); |
20 |
}, |
21 |
|
22 |
jsonParseFilter: function (key, value) { |
23 |
if(value != null && typeof value == "object" && value.__CLASS__) { |
24 |
return Joose.Storage.Unpacker.unpack(value) |
25 |
} |
26 |
return value |
27 |
}, |
28 |
|
29 |
patchJSON: function () { |
30 |
var orig = JSON.parse; |
31 |
JSON.parse = function (s, filter) { |
32 |
return orig(s, function (key, value) { |
33 |
var val = value; |
34 |
if(filter) { |
35 |
val = filter(key, value) |
36 |
} |
37 |
return Joose.Storage.Unpacker.jsonParseFilter(key,val) |
38 |
}) |
39 |
} |
40 |
} |
41 |
} |
42 |
}) |