How to use the @ember-data/serializer/json.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 NREL / api-umbrella / src / api-umbrella / admin-ui / app / serializers / application.js View on Github external
import JSONSerializer from '@ember-data/serializer/json';
import { underscore } from '@ember/string';

export default JSONSerializer.extend({
  // Use camel-cased attribute names in the JS models, but underscore the
  // attribute names for any server-side communication.
  keyForAttribute(attr) {
    return underscore(attr);
  },

  // For single records, look for the data under the customizable
  // "singlePayloadKey" attribute name on the response.
  normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
    let key = primaryModelClass.singlePayloadKey;
    if(key) {
      payload = payload[key];
    }

    return this._super(store, primaryModelClass, payload, id, requestType);
  },
github emberjs / data / packages / serializer / addon / json-api.js View on Github external
extractRelationship(relationshipHash) {
      let normalizedRelationship = this._super(...arguments);

      // Customize relationship meta
      normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);

      return normalizedRelationship;
    }
  });

@since 1.13.0 @class JSONAPISerializer @extends JSONSerializer / const JSONAPISerializer = JSONSerializer.extend({ /* @method _normalizeDocumentHelper @param {Object} documentHash @return {Object} @private */ _normalizeDocumentHelper(documentHash) { if (typeOf(documentHash.data) === 'object') { documentHash.data = this._normalizeResourceHelper(documentHash.data); } else if (Array.isArray(documentHash.data)) { let ret = new Array(documentHash.data.length);

  for (let i = 0; i < documentHash.data.length; i++) {
    let data = documentHash.data[i];
    ret[i] = this._normalizeResourceHelper(data);
  }
github emberjs / data / packages / unpublished-fastboot-test-app / app / serializers / application.ts View on Github external
import JSONSerializer from '@ember-data/serializer/json';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default JSONSerializer.extend(EmbeddedRecordsMixin, {});
github emberjs / data / packages / serializer / addon / rest.js View on Github external
export default RESTSerializer.extend({
    keyForAttribute(attr, method) {
      return underscore(attr).toUpperCase();
    }
  });

You can also implement keyForRelationship, which takes the name of the relationship as the first parameter, the kind of relationship (hasMany or belongsTo) as the second parameter, and the method (serialize or deserialize) as the third parameter.

@class RESTSerializer @extends JSONSerializer / const RESTSerializer = JSONSerializer.extend({ /* keyForPolymorphicType can be used to define a custom key when serializing and deserializing a polymorphic type. By default, the returned key is ${key}Type.

Example

```app/serializers/post.js
import RESTSerializer from '@ember-data/serializer/rest';

export default RESTSerializer.extend({
  keyForPolymorphicType(key, relationship) {
    var relationshipKey = this.keyForRelationship(key);

    return 'type-' + relationshipKey;
  }

@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 18 days ago

Package Health Score

89 / 100
Full package analysis