« All deprecation guides

Deprecation Guide for JSONAPISerializer.payloadKeyFromModelName for Resource

until: 4.0.0
id: jsonapiserializer-payloadkeyfrommodelname-for-resource

feature: ds-payload-type-hooks

Using JSONAPISerializer.payloadKeyFromModelName to serialize the type of a model has been deprecated in favor of JSONAPISerializer.payloadTypeFromModelName.

For example, if your API expects a namespaced resource type in the payload that is sent when you create a post model:

// POST /api/posts/1

{
  "data": {
    "id": 1,
    "type": "api::v1::post"
  }
}

Previously, you would want to override payloadKeyFromModelName to add the namespace to the modelName:

app/serializers/post.js
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
  payloadKeyFromModelName(modelName) {
    return `api::v1::${modelName}`;
  }
});

You can remove this deprecation by refactoring your serializer to instead use payloadTypeFromModelName:

app/serializers/post.js
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
  payloadTypeFromModelName(modelName) {
    return `api::v1::${modelName}`;
  }
});