chore: 🤖 empty strings should be serialized as null

This commit is contained in:
Randall Morey committed 2020-10-07 10:53:53 -04:00
1 parent 31459254f2
commit ce08ae3001
2 files changed
+19 -1

No files matched your search

+4 -1
View File
@@ -37,8 +37,11 @@ export default class ApplicationSerializer extends RESTSerializer {
* @param {String} key
* @param {Object} attribute
*/
serializeAttribute(snapshot, json, key, { options }) {
serializeAttribute(snapshot, json, key, attribute) {
const { type, options } = attribute;
let value = super.serializeAttribute(...arguments);
// Convert empty strings to null.
if (type === 'string' && json[key] === '') json[key] = null;
// Do not serialize read-only attributes.
if (options.readOnly) delete json[key];
// Version is sent only if it has a non-nullish value