Custom Serializer for "type"

Hi there

I’ve read the guide for custom serializers Customizing Serializers - Ember Data - Ember Guides and I wanted to extend my application serializer with a specific format for the style info in the json-output:

import JSONAPISerializer from '@ember-data/serializer/json-api';
import { underscore } from '@ember/string';

export default JSONAPISerializer.extend({
	keyForAttribute(attr) {
		return underscore(attr);
	},
	keyForRelationship(key) {
		return underscore(key);
	}
});

I want to underscore the “type” info but there’s no keyForType or something similar.

{
  "data": {
    "type": "people",    //<-----this type
    "id": "123",
    "attributes": {
      "given-name": "Jeff",
      "family-name": "Atwood"
    }
  }
}

Do I miss something or is this solved an other way.

Thank you

Michael

It’s weirdly named but I think modelNameFromPayloadKey might be what you want?

1 Like

Thank you, I’ve found the correct one. In my case it was JSONAPISerializer - 3.25 - Ember API Documentation.

1 Like