src/resource/Resource.js
/**
   * Opposite of serialization. Convert API responses into proper Entities
   * using the entity class of the resource. If response is a collection,
   * converts each of the items.
   *
   * @param {Object} response - JSON response from API
   * @returns {Object|Entity|Response} - Entity if able to deserialize;
   * Response if fullResponse option was used; Object otherwise.
   */
Opposite of serialization. Convert API responses into proper Entities
using the entity class of the resource. If response is a collection,
converts each of the items.

@param {Object} response - JSON response from API
@returns {Object|Entity|Response} - Entity if able to deserialize;
Response if fullResponse option was used; Object otherwise.
Opposite of serialization . Convert API responses into proper Entities using the entity class of the resource . If response is a collection converts each of the items . @param { Object } response - JSON response from API @returns { Object|Entity|Response } - Entity if able to deserialize ; Response if fullResponse option was used ; Object otherwise .
deserialize (response) {
    if (response && this.type) {
      if (Array.isArray(response)) {
        if (typeof response[0] === 'object') {
          return response.map(this.deserialize.bind(this))
        } else {
          return response
        }
      }
      if (response.body) {
        response.deserialize = () => response.json().then(this.deserialize.bind(this))
      } else {
        let newPath = this.path
        if (response.id && newPath.indexOf(response.id) === -1) {
          newPath += `/${response.id}`
        }
        const newResource = new Resource(this.scope, newPath, this.type)
        const EntityType = this.type
        return new EntityType(newResource, response)
      }
    }
    return response
  }
deserialize ( response ) { if ( response && this . type ) { if ( Array . isArray ( response ) ) { if ( typeof response [ 0 ] === 'object' ) { return response . map ( this . deserialize . bind ( this ) ) } else { return response } } if ( response . body ) { response . deserialize = ( ) => response . json ( ) . then ( this . deserialize . bind ( this ) ) } else { let newPath = this . path if ( response . id && newPath . indexOf ( response . id ) === - 1 ) { newPath += ` ${ response . id } ` } const newResource = new Resource ( this . scope , newPath , this . type ) const EntityType = this . type return new EntityType ( newResource , response ) } } return response }
Opposite of serialization.
Opposite of serialization .
// Deserialise each item, if they're objects // Basic string type // Full response, add deserialize method to deserialize the Response's // json body // JSON response, base case. // Create new entity with updated resource derived from current. // Expand resource path with ID of entity.