ason
ason copied to clipboard
feat: add decorator for class to be serializable and fix types file
Now you must add @ason
to a class for the transform to take place. Library files are an exception. Also added Ason class to index.d.ts
.
I was trying to make ASON accessible with minimal steps for the end user. If they had to explicitly annotate a class, it might be cumbersome.
Another example might be a library that wants to support ason. Currently the only requirement might be adding manual asonSerialize methods. That method works really well for libraries like temporal who only need to store a single integer to Serialize their references.
The problem comes for developers who require the ASON default Serializer. They can add the decorator to opt into default serialization, but that requires the end user to transform their source with @ason/transform
.
Two solutions:
- Document it and accept the downside
- Provide a default asconfig to extend which potentially causes trouble for end users.
I think this makes disharmony.
Why is this feature necessary?
I'm also not sure why this is necessary.
JSON serializers/deserializers don't require annotations for objects to be serialized/deserialized; except for special cases such as values that should be JsonIgnore
d. Those such cases are currently handled with the customizable __asonSerialize()
and __asonDeserialize()
I'm all for some kind of annotation similar to a JsonIgnore
, that will allow for some fields to be ignored without explicitly defining the custom serialize/deserialize.