Is it possible to serialize ES6 class type having object instance? How?
class MyClass {
}
let myClass = new MyClass()
//store class type
let clazzTypeString = serializeClassTypeToString(myClass)
let myClassString = JSON.stringify(myClass)
//restore
let MyClassConstructor = restoreClassTypeFromString(clazzTypeString)
let myClassRestored = Object.assign(new MyClassConstructor(), JSON.parse(myClassString))
I'm trying to figure out implementation of serializeClassTypeToString and restoreClassTypeFromString
I'm trying to serialize/deserialize ES6 objects inside my application, but this process needs to be fully dynamic.
I know I can store a prop in object that points to a type and than to have a map of string->constructor. This isn't a solution I'm looking for.
I assume I need to store the path to the class file and then import it to get constructor, but I also suspect that class instance doesn't store the path information.
Or maybe eval?
My knowledge is limited when it comes to the internal organisation of ES6 classes and instances (rather than "it's just a function") and any input on that is much appreciated.