jsonapi-serializer icon indicating copy to clipboard operation
jsonapi-serializer copied to clipboard

feat: On deserialization it would be nice if the meta, links, etc, are available as a Symbol in the data

Open diosney opened this issue 6 years ago • 0 comments

Right now after deserialization, we don't have access to the meta data like meta, links and so on, only to the data itself.

This has a caveat, that if we pass or return that data to another method, we lose access to that meta data and forces us now to destructure it before deserialization to pass it as an extra param.

This could be easily solved if that meta data is returned as a non enumerable, non writable, non configurable property keyed with a Symbol, to avoid clashes, so we can have access to it at any time if we have a reference to the deserialized data itself.

For instance:

let deserializedData: any = new JsonApiSerializer
          .Deserializer(JSON_DESERIALIZER_DEFAULT_OPTIONS)
          .deserialize(jsonApiResponse);

console.log(deserializedData[JsonApiSerializer.EXTRAS_SYMBOL]); 

// Example output could be:
{
   extras: {
     links: {...},
     meta: {...}
   }
}

// Extras Symbol could be something like:
JsonApiSerializer.EXTRAS_SYMBOL = new Symbol('json-api-serializer-extras-symbol');

diosney avatar Sep 25 '19 23:09 diosney