Skip to content

Instantly share code, notes, and snippets.

@davydotcom
Created January 14, 2014 16:23
Show Gist options
  • Save davydotcom/8421052 to your computer and use it in GitHub Desktop.
Save davydotcom/8421052 to your computer and use it in GitHub Desktop.
Ember data working with grails style json
DS.RESTAdapter.reopen({
pathForType: function(type) {
return Ember.String.camelize(type);
}
});
App.ApplicationSerializer = DS.RESTSerializer.extend({
normalizePayload: function(type, payload) {
console.log("normalizing things");
if(payload.data instanceof Array) {
payload[Ember.String.pluralize(type.typeKey)] = payload.data;
delete payload.data;
} else {
console.log(Ember.String.singularize(type.typeKey))
payload[Ember.String.singularize(type.typeKey)] = payload.data;
delete payload.data;
}
console.log(payload)
return payload;
},
serializeIntoHash: function(data, type, record, options) {
var object = this.serialize(record, options);
for(var key in object) {
data[key] = object[key];
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment