home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
4.12
  • Packages
    • @ember-data/adapter
    • @ember-data/adapter/error
    • @ember-data/adapter/json-api
    • @ember-data/adapter/rest
    • @ember-data/canary-features
    • @ember-data/debug
    • @ember-data/deprecations
    • @ember-data/experimental-preview-types
    • @ember-data/graph
    • @ember-data/json-api
    • @ember-data/legacy-compat
    • @ember-data/model
    • @ember-data/request
    • @ember-data/request/fetch
    • @ember-data/serializer
    • @ember-data/serializer/json
    • @ember-data/serializer/json-api
    • @ember-data/serializer/rest
    • @ember-data/store
    • @ember-data/tracking
  • Classes
    • <Interface> Adapter
    • <Interface> Cache
    • <Interface> Handler
    • <Interface> Serializer
    • AbortError
    • Adapter
    • AdapterError
    • BelongsToReference
    • BooleanTransform
    • BuildURLMixin
    • Cache
    • CacheManager
    • CacheStoreWrapper
    • CanaryFeatureFlags
    • ConflictError
    • CurrentDeprecations
    • DateTransform
    • DebugLogging
    • EmbeddedRecordsMixin
    • Errors
    • Fetch
    • ForbiddenError
    • Future
    • HasManyReference
    • IdentifierCache
    • InvalidError
    • JSONAPIAdapter
    • JSONAPISerializer
    • JSONSerializer
    • ManyArray
    • Model
    • NotFoundError
    • NotificationManager
    • NumberTransform
    • PromiseArray
    • PromiseManyArray
    • PromiseObject
    • RESTAdapter
    • RESTSerializer
    • RecordArray
    • RecordReference
    • RequestManager
    • RequestStateService
    • SchemaService
    • Serializer
    • ServerError
    • Snapshot
    • SnapshotRecordArray
    • StableRecordIdentifier
    • Store
    • StringTransform
    • TimeoutError
    • Transform
    • UnauthorizedError

Class Serializer public


Extends: Ember.EmberObject
Defined in: ../serializer/src/index.ts:115
Module: @ember-data/serializer

⚠️ CAUTION you likely want the docs for Serializer as extending this abstract class is unnecessary.

Serializer is an abstract base class that you may override in your application to customize it for your backend. The minimum set of methods that you should implement is:

  • normalizeResponse()
  • serialize()

And you can optionally override the following methods:

  • normalize()

For an example implementation, see JSONSerializer, the included JSON serializer.


Methods

normalize (typeClass, hash) : Object public

Module: @ember-data/serializer

Defined in ../packages/serializer/src/index.ts:240

typeClass
Model
hash
Object
returns
Object

The normalize method is used to convert a payload received from your external data source into the normalized form store.push() expects. You should override this method, munge the hash and return the normalized payload.

Example:

Serializer.extend({
  normalize(modelClass, resourceHash) {
    let data = {
      id:            resourceHash.id,
      type:          modelClass.modelName,
      attributes:    resourceHash
    };
    return { data: data };
  }
})

normalizeResponse (store, primaryModelClass, payload, id, requestType) : Object public

Module: @ember-data/serializer

Defined in ../packages/serializer/src/index.ts:162

Available since v1.13.0

store
Store
primaryModelClass
Model
payload
Object
id
String|Number
requestType
String
returns
Object

JSON-API Document

The normalizeResponse method is used to normalize a payload from the server to a JSON-API Document.

http://jsonapi.org/format/#document-structure

Example:

Serializer.extend({
  normalizeResponse(store, primaryModelClass, payload, id, requestType) {
    if (requestType === 'findRecord') {
      return this.normalize(primaryModelClass, payload);
    } else {
      return payload.reduce(function(documentHash, item) {
        let { data, included } = this.normalize(primaryModelClass, item);
        documentHash.included.push(...included);
        documentHash.data.push(data);
        return documentHash;
      }, { data: [], included: [] })
    }
  }
});

serialize (snapshot, options) : Object public

Module: @ember-data/serializer

Defined in ../packages/serializer/src/index.ts:198

snapshot
Snapshot
options
Object
returns
Object

The serialize method is used when a record is saved in order to convert the record into the form that your external data source expects.

serialize takes an optional options hash with a single option:

  • includeId: If this is true, serialize should include the ID in the serialized object it builds.

Example:

Serializer.extend({
  serialize(snapshot, options) {
    let json = {
      id: snapshot.id
    };

    snapshot.eachAttribute((key, attribute) => {
      json[key] = snapshot.attr(key);
    });

    snapshot.eachRelationship((key, relationship) => {
      if (relationship.kind === 'belongsTo') {
        json[key] = snapshot.belongsTo(key, { id: true });
      } else if (relationship.kind === 'hasMany') {
        json[key] = snapshot.hasMany(key, { ids: true });
      }
    });

    return json;
  },
});

Properties

store public

Module: @ember-data/serializer

Defined in ../packages/serializer/src/index.ts:140

The store property is the application's store that contains all records. It can be used to look up serializers for other model types that may be nested inside the payload response.

Example:

Serializer.extend({
  extractRelationship(relationshipModelName, relationshipHash) {
    let modelClass = this.store.modelFor(relationshipModelName);
    let relationshipSerializer = this.store.serializerFor(relationshipModelName);
    return relationshipSerializer.normalize(modelClass, relationshipHash);
  }
});
On this page


Methods

  • normalize
  • normalizeResponse
  • serialize

Properties

  • store
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.