/serializer

Utility to serialize/deserialize js object and restore its context as close as possible

Primary LanguageTypeScriptMIT LicenseMIT

serializer

Utility to serialize/deserialize js object and restore its context as close as possible

Motivation

In JS:

  • We have no "classpaths", so we cannot bind class ref with its package/module.
  • JSON.serialize, v8.serialize does not produce any meta that could be used to restore object context (proto, bindings).

There're... just a few JSON supersets that change the situation slightly: json-schema, serialize-javascript Therefore, yet another one incompatible format does not affect anything.

Suggestions

  • Serialized data should describe itself by meta (something like as regular file does: header + ext)
  • Classes refs may be found by scanning require.cache inners or globals

Status

🚧 Work in progress 🚧 / Experimental / Early preview / pre-alpha version / 0.0.0-draft

Install

yarn add @qiwi/serializer

Usage

import {serialize, deserialize} from '@qiwi/serializer'
import {A} from './A'

const a: A = new A()
const serialized: string = serialize(a)
const restored: A = deserialize(serialized)

console.log(restored instanceof A) // true

Refs