jsonapi-serializer
jsonapi-serializer copied to clipboard
How to keep top level meta object after deserialization?
In my API response I have a top level 'meta' object (including pagination info) and a top level 'data' object. How can I keep the 'meta' object after deserialization?
Same here, no one can help?
@kuiperr005 @schermannj How did you guys end up solving the issue?
@Princu7 Not in the best way in my case.
Something like this:
`
...
request.then((resp) => { // resp is a jso-api serialized data object
const data = new JSONAPIDeserializer().deserialize(resp);
Object.assign(data, { meta: resp.meta });
console.log(data);
})
` So if it's possible to fix it somehow, it would be great.
I did exactly like @Princu7, not the best way in my opinion too.
@schermannj @kuiperr005 Thanks for the response Guys. I did a little investigation on this issue and the reason why it is like that is that the meta object is not meant to be deserialized. It is not a part of the original data which was serialized. It just contains some additional information about the data we received.
If we want the top-level meta object to deserialize, we can follow the same approach that has been done to deserialize the top-level links object. It's very easy. See this PR https://github.com/SeyZ/jsonapi-serializer/commit/12bd9bc5ce64e75f0a9f6b6e7d8fa56c2d64eaf3 Just at the point where the extra lines have been added, add these lines below it:-
if (jsonapi.meta) {
record.meta = jsonapi.meta;
}
It should work fine :)
@Princu7 It sounds fine, when are you going to push these changes?
@SeyZ I think this issue is related to https://github.com/SeyZ/jsonapi-serializer/issues/84. The links that are currently supported could be moved to record.meta.links
maybe?
Has this been implemented yet? Or if not, any alternative workarounds?