import DS from 'ember-data';

export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    aggregatedHistory: { embedded: 'always' }
  },
  normalizePayload: function(payload) {
    delete payload._type;
    delete payload.className;
    delete payload._embedded;

    payload.conversation = payload.conversation.$id.$oid;
    payload.statistics = payload.statistics.$id.$oid;

    for(var i = 0; i < payload.participants.length; i++) {
      payload.participants[i] = payload.participants[i].$id.$oid;
    }

    for(var i = 0; i < payload.aggregatedHistory.length; i++) {
      payload.aggregatedHistory[i].id = payload.aggregatedHistory[i]._id.$oid;
      payload.aggregatedHistory[i].statistics.id = payload.aggregatedHistory[i]._id.$oid;
    }


    payload.id = payload._id.$oid;
    delete payload._id.$oid;

    console.log(payload);
    return payload;
  }
});

@@ -753,24 +753,218 @@
 %5D._id.$oid;%0A
+      payload.aggregatedHistory%5Bi%5D.startInstant = payload.aggregatedHistory%5Bi%5D.startInstant.$date;%0A      payload.aggregatedHistory%5Bi%5D.endInstant = payload.aggregatedHistory%5Bi%5D.endInstant.$date;%0A
     %7D%0A%0A%0A    

bugfix. date transformed in serializer