-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
The following minimal test case (in typescript) reveals a potential bug where a reference is undefined after revive through user defined conversion:
const Typeson = require('typeson');
class ComplexClassThroughArray {
constructor(public x = {}) {
}
}
const typeson = new Typeson().register({
ComplexClassThroughArray: [
(x: any) => x instanceof ComplexClassThroughArray, // test function
(d: ComplexClassThroughArray) => [d.x], // encapsulator function
(d: Array<object>) => { // reviver function
return new ComplexClassThroughArray(d[0]);
}
],
});
it('revive_complex_class_through_array', () => {
const o = new ComplexClassThroughArray();
const json = JSON.stringify(typeson.encapsulate({
o,
x: o.x
}));
const r = typeson.revive(JSON.parse(json));
expect(r.x).toStrictEqual(o.x);
});This test fails at the very end because r.x is undefined.
The json variable has the serialized value {"o":[{}],"x":"#o.0","$types":{"o":"ComplexClassThrughArray","x":"#"}}.
The same problem appears if you replace ComplexClassThroughArray with the built-in type Set, which has basically an identical user defined conversion in typeson-registry.
Could it be that the reference in "x":"#o.0" does get resolved after "o":[{}] has been revived rendering the json path invalid?
Reactions are currently unavailable