question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

serializeAndPush requires jsonapi.version, but spec does not

See original GitHub issue

Right now the serializeAndPush checks the response for a { jsonapi: { version: * } fragment, even though the JSON API spec says the following:

A JSON:API document MAY include information about its implementation under a top level jsonapi member. If present, the value of the jsonapi member MUST be an object (a “jsonapi object”). The jsonapi object MAY contain a version member whose value is a string indicating the highest JSON API version supported.

My interpretation of this is that serializeAndPush is more strict than it should be, but I do understand this is probably included to inform users that this function is only compatible with a JSON API compliant API. An alternative would be to not return from this function, but just display the warning.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mike-northcommented, Nov 25, 2018

@iezer that’s more generalized than I’m comfortable with. We need to auto-detect things that are definitely JSON:API documents without any false positives (i.e., this serializeAndPush feature should never get in the way, and should clearly announce that specific payload shapes are required if anything looks “off”).

If I have a payload

{ 
   "data": [
     "a", "b", "c"
   ]
}

I should get very clear feedback that this can’t be used with serializeAndPush.

Maybe update isJsonApi to something like

Payload has a data property, that’s either a record or array of records. A record must contain id and type properties of type string, and may contain an attributes property whose value is an object

0reactions
mike-northcommented, Nov 28, 2018

I wonder if there’s another function we can use within Ember Data that can call normalizeSingleResponse or normalizeArrayResponse depending on the input, and will work regardless of serialization format.

What you’re looking for is normalizeResponse. Depending on the requestType argument that it’s passed, it’ll look for the payload to contain a single record or array of records. https://github.com/emberjs/data/blob/3dc5976ed5565708ac0813e5c2beb46f31f4d44f/addon/serializers/json.js#L239-L262

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsonapi-serializers/README.md at master - GitHub
This library is up-to-date with the finalized v1 JSON API spec. Features; Installation; Usage. Define a serializer; Serialize an object; Serialize a collection ......
Read more >
ASP.NET Core 3.1 How can I get the controller to use System ...
I am unable to get System.Text.Json to bind the model by parsing with application/vnd.api+json - the model is NULL. It will only bind ......
Read more >
Customizing Serializers - Ember Data
In Ember Data, serializers format the data sent to and received from the backend store. By default, Ember Data serializes data using the...
Read more >
Try the new System.Text.Json source generator - .NET Blog
Json source generator, we now have a few models for JSON serialization in .NET to choose from, using JsonSerializer . There is the...
Read more >
REST API Developer Guide
A primary benefit of REST API is that it doesn't require much tooling to access your data. It's simpler to use than SOAP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found