From a93e95d2595e032b6fb49fe1974a3b3da5f567bb Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 7 Dec 2020 12:28:23 -0800 Subject: [PATCH] Guard against a null Meta property in the scale event API --- ui/app/serializers/application.js | 18 ++++++++++++++++++ ui/app/serializers/scale-event.js | 1 + 2 files changed, 19 insertions(+) diff --git a/ui/app/serializers/application.js b/ui/app/serializers/application.js index 32ddd21ed..d180cc62c 100644 --- a/ui/app/serializers/application.js +++ b/ui/app/serializers/application.js @@ -20,6 +20,17 @@ export default class Application extends JSONSerializer { */ arrayNullOverrides = null; + /** + A list of keys that are converted to empty objects if their value is null. + + objectNullOverrides = ['Object']; + { Object: null } => { Object: {} } + + @property objectNullOverrides + @type String[] + */ + objectNullOverrides = null; + /** A list of keys or objects to convert a map into an array of maps with the original map keys as Name properties. @@ -90,6 +101,13 @@ export default class Application extends JSONSerializer { } }); } + if (this.objectNullOverrides) { + this.objectNullOverrides.forEach(key => { + if (!hash[key]) { + hash[key] = {}; + } + }); + } if (this.mapToArray) { this.mapToArray.forEach(conversion => { diff --git a/ui/app/serializers/scale-event.js b/ui/app/serializers/scale-event.js index a8dea78b6..bbcfb3f97 100644 --- a/ui/app/serializers/scale-event.js +++ b/ui/app/serializers/scale-event.js @@ -2,4 +2,5 @@ import ApplicationSerializer from './application'; export default class ScaleEventSerializer extends ApplicationSerializer { separateNanos = ['Time']; + objectNullOverrides = ['Meta']; }