How to use the @ember-data/serializer.extend function in @ember-data/serializer

To help you get started, we’ve selected a few @ember-data/serializer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / data / packages / serializer / addon / json.js View on Github external
The `JSONSerializer` normalization process follows these steps:

    - `normalizeResponse` - entry method to the serializer.
    - `normalizeCreateRecordResponse` - a `normalizeResponse` for a specific operation is called.
    - `normalizeSingleResponse`|`normalizeArrayResponse` - for methods like `createRecord` we expect
      a single record back, while for methods like `findAll` we expect multiple records back.
    - `normalize` - `normalizeArray` iterates and calls `normalize` for each of its records while `normalizeSingle`
      calls it once. This is the method you most likely want to subclass.
    - `extractId` | `extractAttributes` | `extractRelationships` - `normalize` delegates to these methods to
      turn the record payload into the JSON API format.

  @class JSONSerializer
  @extends Serializer
*/
const JSONSerializer = Serializer.extend({
  /**
    The `primaryKey` is used when serializing and deserializing
    data. Ember Data always uses the `id` property to store the id of
    the record. The external source may not always follow this
    convention. In these cases it is useful to override the
    `primaryKey` property to match the `primaryKey` of your external
    store.

    Example

    ```app/serializers/application.js
    import JSONSerializer from '@ember-data/serializer/json';

    export default JSONSerializer.extend({
      primaryKey: '_id'
    });

@ember-data/serializer

Provides Legacy JSON, JSON:API and REST Implementations of the Serializer Interface for use with @ember-data/store

MIT
Latest version published 1 day ago

Package Health Score

92 / 100
Full package analysis