{"id":15609,"library":"esserializer","title":"ESSerializer","description":"ESSerializer is a JavaScript serialization and deserialization utility. It enables the conversion of JavaScript class instances into JSON format and their subsequent reconstruction back into fully functional objects, ensuring that all Class, Property, and Method information is retained recursively. The library operates without relying on `eval()`, which eliminates a common security vulnerability associated with many serialization methods. ESSerializer supports a broad spectrum of built-in JavaScript classes and types, including various Array types, Date, RegExp, BigInt, and all standard Error classes. It is designed to work seamlessly in both browser and Node.js environments. The current stable version, 1.3.11, receives ongoing maintenance with recent releases focusing on minor bug fixes and security vulnerability patches, indicating an active development and stable release cadence. Its key differentiators include robust recursive class retention, automatic class definition detection during serialization and deserialization, comprehensive support for getter/setter properties and `instanceof` checks, and compatibility with both modern ES6 classes and older function-style class definitions.","status":"active","version":"1.3.11","language":"javascript","source_language":"en","source_url":"https://github.com/shaochuancs/esserializer","tags":["javascript","serialization","deserialization","typescript"],"install":[{"cmd":"npm install esserializer","lang":"bash","label":"npm"},{"cmd":"yarn add esserializer","lang":"bash","label":"yarn"},{"cmd":"pnpm add esserializer","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESSerializer is a default export.","wrong":"import { ESSerializer } from 'esserializer';","symbol":"ESSerializer","correct":"import ESSerializer from 'esserializer';"},{"note":"CommonJS require pattern for Node.js environments.","symbol":"ESSerializer","correct":"const ESSerializer = require('esserializer');"},{"note":"For TypeScript, you can use `typeof ESSerializer` for type inference of the main utility object.","symbol":"ESSerializer","correct":"type ESSerializerType = typeof ESSerializer;"}],"quickstart":{"code":"import ESSerializer from 'esserializer';\n\nclass ClassC {\n  constructor(public value: number) {}\n  getDoubled(): number { return this.value * 2; }\n}\n\nclass ClassB {\n  constructor(public name: string, public cInstance: ClassC) {}\n  greet(): string { return `Hello from ${this.name}! C's doubled value: ${this.cInstance.getDoubled()}`; }\n}\n\nclass ClassA {\n  private id: string;\n  public date: Date;\n  public bInstance: ClassB;\n  public myArray: number[];\n\n  constructor(id: string) {\n    this.id = id;\n    this.date = new Date();\n    this.bInstance = new ClassB('Nested B', new ClassC(10));\n    this.myArray = [1, 2, 3];\n  }\n\n  getId(): string { return this.id; }\n  getDetails(): string {\n    return `ID: ${this.id}, Date: ${this.date.toISOString()}, B's greeting: ${this.bInstance.greet()}, Array: ${this.myArray.join(',')}`;\n  }\n}\n\nconst originalObj = new ClassA('unique-123');\nconsole.log('Original object details:', originalObj.getDetails());\nconsole.log('Original object B instance greet:', originalObj.bInstance.greet());\n\n// Serialize the object\nconst serializedString = ESSerializer.serialize(originalObj);\nconsole.log('Serialized string (truncated):', serializedString.substring(0, 100) + '...');\n\n// Deserialize the object, providing custom classes\nconst deserializedObj = ESSerializer.deserialize(serializedString, [ClassA, ClassB, ClassC]);\n\nconsole.log('Deserialized object details:', deserializedObj.getDetails());\nconsole.log('Deserialized object B instance greet:', deserializedObj.bInstance.greet());\n\n// Verify instance types and methods\nconsole.assert(deserializedObj instanceof ClassA, 'Deserialized object is not an instance of ClassA');\nconsole.assert(deserializedObj.bInstance instanceof ClassB, 'Nested object is not an instance of ClassB');\nconsole.assert(deserializedObj.bInstance.cInstance instanceof ClassC, 'Deeply nested object is not an instance of ClassC');\nconsole.assert(typeof deserializedObj.getId === 'function', 'getId method missing');\nconsole.assert(deserializedObj.getId() === 'unique-123', 'ID mismatch');\nconsole.assert(deserializedObj.date instanceof Date, 'Date object not retained');\n\nconsole.log('Serialization and deserialization successful!');","lang":"typescript","description":"This quickstart demonstrates the serialization and deserialization of nested class instances, verifying method and type retention."},"warnings":[{"fix":"Update esserializer to version `1.3.7` or later: `npm install esserializer@latest`","message":"Versions prior to `1.3.7` contained unpatched vulnerabilities. Users should upgrade to `1.3.7` or newer immediately for security fixes.","severity":"breaking","affected_versions":"<1.3.7"},{"fix":"For these advanced use cases, refer to the 'ESSerializer Pro' documentation or implement custom serialization/deserialization logic for specific types.","message":"Advanced features like serialization of `Map`, `Set` with complex keys, `Symbol` types, and circular object structures are only available in 'ESSerializer Pro' or via specific options. The base `esserializer` package may not handle these scenarios out-of-the-box or may require manual configuration.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure all custom class definitions are passed in an array to `ESSerializer.deserialize(serializedString, [ClassA, ClassB, ...])`.","message":"When deserializing, custom classes involved in the object graph *must* be provided as the second argument to `ESSerializer.deserialize()`. Failing to do so will result in generic objects or lost methods/instanceof checks.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Pass all custom class definitions as an array to `ESSerializer.deserialize(serializedString, [ClassName1, ClassName2, ...])`.","cause":"During deserialization, a custom class required for reconstruction was not provided to `ESSerializer.deserialize()`.","error":"ReferenceError: ClassName is not defined"},{"fix":"Verify that all relevant class definitions are correctly imported and passed to the `deserialize` method. For example: `ESSerializer.deserialize(serializedData, [MyCustomClass]);`","cause":"The deserialized object did not correctly retain its class methods. This often happens if the class definitions were not supplied during deserialization or were incorrect.","error":"TypeError: instance.methodName is not a function"},{"fix":"Either refactor your object structure to avoid circular references, or consider using 'ESSerializer Pro' which explicitly supports this feature.","cause":"Attempting to deserialize an object with circular references using the standard `esserializer` package.","error":"Error: Cannot deserialize circular structure without ESSerializer Pro."},{"fix":"For ES Modules: `import ESSerializer from 'esserializer';`. For CommonJS: `const ESSerializer = require('esserializer');`.","cause":"Incorrect import of the `ESSerializer` module, typically trying to use a named import instead of the default export in an ES module context, or vice-versa in CommonJS.","error":"TypeError: ESSerializer.serialize is not a function"}],"ecosystem":"npm"}