I'm consuming a web service that in POST/PUT verbs expects a JSON like this:
{
"id":"CACTU",
"companyName": "Cactus Comidas para llevar",
"contactName": "Patricio Simpson",
"contactTitle": "Sales Agent",
"address": "Cerrito 333",
"city": "Buenos Aires",
"postalCode": "1010",
"country": "Argentina",
"phone": "(1) 135-5555",
"fax": "(1) 135-4892"
}
But Ember Data sends a JSON like this:
{
"customer":
{
"id":"CACTU",
"companyName": "Cactus Comidas para llevar",
"contactName": "Patricio Simpson",
"contactTitle": "Sales Agent",
"address": "Cerrito 333",
"city": "Buenos Aires",
"postalCode": "1010",
"country": "Argentina",
"phone": "(1) 135-5555",
"fax": "(1) 135-4892"
}
}
How I can delete "customer" root element when sending POST/PUT operations?
You'll want to override one of the serialize methods, I think serializeIntoHash might work:
App.CustomerSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
Ember.merge(hash, this.serialize(record, options));
}
});
This is instead of the normal serializeIntoHash which looks like this:
serializeIntoHash: function(hash, type, record, options) {
hash[type.typeKey] = this.serialize(record, options);
}
Additional documentation can be found here:
https://github.com/emberjs/data/blob/v2.1.0/packages/ember-data/lib/serializers/rest-serializer.js#L595
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With