Custom Serializer for non-Ember style API?


#1

Assuming that my JSON Payload looks something like this:

{
  "status": "string",
  "data": {
    "debtor": {
      "debtor_id": "integer",
      "debtor_contact_id": "integer",
      "debtor_type": "string",
      "debtor_balance": "float",
      "debtor_next_contact_date": "dateTime",
      "debtor_tax_id": "string",
      "debtor_timezone": "string",
      "debtor_full_name": "string",
      "debtor_first_name": "string",
      "debtor_last_name": "string",
      "debtor_middle_initial": "string",
      "debtor_salutation": "string",
      "debtor_email": "string"
    }
  },
  "message": "string",
  "code": "string"
}

How can I write a serializer/de-serializer that can format a record the way Ember-Data wants?

The data is two levels deep… and i know how to set a primaryKey to “debtor_id”… but “data” is a root key, and “debtor” is i guess like a collection key… but i don’t know if Ember-Data has any built-in methods to address those keys?

Edit: this particular example is just a return of a single record, but could the same serializer be used on a collection? or would i need a custom one for that as well…?