Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve serialization (handle arbitrary circular references) #33

Open
1j01 opened this issue Sep 1, 2024 · 0 comments
Open

Improve serialization (handle arbitrary circular references) #33

1j01 opened this issue Sep 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@1j01
Copy link
Owner

1j01 commented Sep 1, 2024

JSON does not (in and of itself) support circular references or multiple references to the same object.
I have some special handling to serialize references to other entities within the top level properties of entities, but this is not general, and it can be confusing that it works at the top level but not e.g. in an array.

There are numerous JavaScript libraries that intend to solve this problem, and many of them also extend the set of types that can be serialized to include undefined, RegExp, Date, etc.

Some of these libraries use JSON as the serial format, keeping keys, but replacing values with a special format.
This can be problematic for fields used for versioning the format, as a formatVersion: 5 may be serialized as formatVersion: 2 because the number 5 is the second (2) value that was serialized. To work around this, I could add such fields to the document after serialization, although most libraries probably do not provide a way to hook in so as to avoid having to reparse the JSON and restringify it. I could include the serialized data under a top level data field, which would either have the same inefficiency (reparsing and restringifying) or, if stored as a string, it would be inefficient on disk.

Here is a list of a bunch of serialization libraries I collected a while back:

@1j01 1j01 added the enhancement New feature or request label Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant