Comments (2)
This reminded me of React's Taint API which usually raises an error when an expected (or in your words, marked) value is encountered during serialization. I did consider this before however there were three reasons why I didn't:
- I didn't like the API. I just don't like marking the value globally.
- The internal map might be a source of memory leak.
- Users can just wrap their own values with an unserializable value.
Now in your case it's a bit different since it doesn't exactly raise an error, it just omits the value. Usually my answer here would be to "defer this problem to the user by making the necessary changes manually" however this might be considered and can open as an opportunity. I like the idea of omitting, but I just need to have a decent API for this.
Here's some of my ideas:
- Introduce a
UnserializableReference
class which is basically just a class with avalue
property that holds the value you want to hide from the serializer e.g.new UnserializableReference(value)
then you can accessvalue
if you want to recover it. - Introduce a
UnserializableReference
abstract class. This is one is just for inheritance check, but not might be ideal. It works, but i'm still 50/50. - Instead of a class, we do an object with an specific symbol. Usually I would provide an API for this (
createUnserializableReference
perhaps)
Now the term unserializable
itself might not be a great term, hidden
might be good replacement term, there's also opaque
, but that's just me. I'd like to discuss the name.
Also, as expected here, if the value is encountered, it's going to be replaced by a new value (by default it would be undefined
HOWEVER I'm thinking of allowing this to be configurable through the reference creation e.g. createUnserializableReference(value, replacement)
), and once the value is serializable, I would expect the users to expect that deserializing the value will not able to recover whatever that value is.
from seroval.
Thanks for looking into the issue! Between the ideas, I like the first and the third one, mostly because the second one requires creating a separate class. For the naming, I also can think of skip
, but I'm happy with anything else 😅 I also love the customizable replacement value idea!
from seroval.
Related Issues (18)
- Feature: well-known symbols
- Feature: Streaming
- Feature: AsyncIterable
- Feature: Global identities HOT 1
- Feature: JSON string serializer HOT 1
- Feature: Structured Clone Algorithm HOT 1
- Support for Class HOT 1
- Better serialization for `Blob` and `File` HOT 1
- Combined types
- Custom serialization API
- serialise date to number instead of string HOT 7
- Edge Case: Mistake on isolating Map entries
- Inside of getCrossReferenceHeader script, getting error Uncaught SyntaxError: Unexpected identifier '_$HY'
- An unhandled error occured: Error: Cannot serialize function without reference ID HOT 2
- Add support for Generator and AsyncGenerator HOT 5
- More support
- serialize 0x prefix string object key as number HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seroval.