Serialize data with empty [] attributes
geoffreyLB opened this issue · 2 comments
When I'm declaring an empty attributes (according to json.api.org) attributes: []
to get default value. I should have first_name, and last_name, but this is what the response looks :
{
"data": {
"data": {
"type": "users",
"id": "1c8877a7-d7e4-4d0a-b3be-c5f62ee17686"
}
}
}
this is what my serializer looks :
new Serializer('user', {
attributes: [],
ref: true,
included: false
});
Indeed, I have the same question.
Are you referring to the fact that, unless the request specifies the fields
query parameter, JSON API responses are supposed to include all attributes (https://jsonapi.org/format/#fetching-sparse-fieldsets)? Because I don't think attributes
corresponds to fields
in that way. attributes
in jsonapi-serializer
just refers to the subset of attributes that should be serialized, out of the set of keys on the data you pass in. For example, your model might include a foreign key field (e.g. author_id
), but you never want that in a JSON API request/response, so you wouldn't ever include it in the attributes list.