This is one of the responsibilities for the Serializer provided by Ember Data. I guess you are using RestSerializer, which is normally used together with RestAdapter aren't you? In that case you should customize the serializeIntoHash() method. Just not using a namespace at all should be accomplished by:
import RESTSerializer from '@ember-data/serializer/rest';
export default RESTSerializer.extend({
serializeIntoHash(data, type, record, options) {
data = this.serialize(record, options);
}
});
To not loose any data that is already present on hash you could use Object.assign(). This is also what's done in JSONSerializer:
import { assign, merge } from '@ember/polyfills';
const emberAssign = assign || merge;
export default RESTSerializer.extend({
serializeIntoHash(hash, typeClass, snapshot, options) {
emberAssign(hash, this.serialize(snapshot, options));
},
});
The assign || merge is only needed to support very old ember versions. You could simplify to:
import { assign } from '@ember/polyfills';
export default RESTSerializer.extend({
serializeIntoHash(hash, typeClass, snapshot, options) {
assign(hash, this.serialize(snapshot, options));
},
});
You don't need to use the polyfill for assign if you don't support IE 11. In that case it would be:
export default RESTSerializer.extend({
serializeIntoHash(hash, typeClass, snapshot, options) {
Object.assign(hash, this.serialize(snapshot, options));
},
});
And with native class it looks like:
export default class ApplicationSerializer extends RESTSerializer {
serializeIntoHash(hash, typeClass, snapshot, options) {
Object.assign(hash, this.serialize(snapshot, options));
}
}