Hi I have a rootless JSON being sent back from my server and I’m using the new JSONAPISerializer. It’s creating a list of models (InternalModels in Ember inspector) and doesn’t seem to have attributes accessible and they seem a unusable. What am I doing wrong?
JSON Format From Server:
[
{
"id": "9819c7035f18d4afb330fae3ed8a2117",
"users": [
"cffa43d600b4fb8af482cd979007d45f",
"6d27bcceb3376df3c8de9b70e9c31505",
"aa71cf51fa4e3ff627d2cc2b44faa689"
],
"name": "Hey",
"owner": "cb30a6aea8b5b693ec682cfac8000bf6",
"last_message": "has added Asdf Asdf",
"last_updated": 1376003828,
"last_id": "cffa43d600b4fb8af482cd979007d45f"
},
{
"id": "61d4325b5dd0682866299282adf8ad5b",
"users": [
"cffa43d600b4fb8af482cd979007d45f"
],
"name": "A",
"owner": "cb30a6aea8b5b693ec682cfac8000bf6",
"last_message": "Test",
"last_updated": 1377046703,
"last_id": "cffa43d600b4fb8af482cd979007d45f"
},.......more entities
Which I convert to this in the serialzier (I tried singluar and plural of type). My Model name is Convo:
{"data":[{"type":"convos","id":"9819c7035f18d4afb330fae3ed8a2117","attributes":{"name":"Hey"}},{"type":"convos","id":"61d4325b5dd0682866299282adf8ad5b","attributes":{"name":"A"}},{"type":"convos","id":"4278da9b2cdf15e06d104dd43fe76857","attributes":{"name":"Hello hello"}},{"type":"convos","id":"65065c01ec81eacaac54793aca239900","attributes":{"name":"Ahoy"}},......more entities
Here is the JSONSerializer code:
export default DS.JSONAPISerializer.extend({
normalizeResponse : function (store, primaryModelClass, payload, id, requestType) {
var payloadType = primaryModelClass.modelName;
var newPayload = {};
newPayload["data"] = payload.map ( function (payloadEntry) {
var newPayloadEntry = {};
newPayloadEntry.type = payloadType;
newPayloadEntry.id = payloadEntry.id;
delete payloadEntry.id;
newPayloadEntry.attributes = {"name" : payloadEntry.name};
return newPayloadEntry;
});
return this._super(store,primaryModelClass,newPayload,id,requestType);
}
});
Any clue why this isn’t working?