diff --git a/src/app/data/vm-template-service-configuration.ts b/src/app/data/vm-template-service-configuration.ts index 327eefdf..d6f60f4e 100644 --- a/src/app/data/vm-template-service-configuration.ts +++ b/src/app/data/vm-template-service-configuration.ts @@ -85,13 +85,27 @@ export function vmServiceToJSON(vmService: VMTemplateServiceConfiguration) { result += ', "noRewriteRootPath": ' + vmService.noRewriteRootPath; } } - if (vmService.cloudConfigMap) { - let cloudConfigMapString = ''; - vmService.cloudConfigMap.forEach((value, key) => { - cloudConfigMapString += '"' + key + '": ' + JSON.stringify(value) + ' '; - }); - result += ', "cloudConfigMap": {' + cloudConfigMapString + '}'; + if (vmService.cloudConfigMap) { + result += ', "cloudConfigMap": {' + mapToJson(vmService.cloudConfigMap, '') + '}'; //Potential alternative if es2019 or higher (configurable in tsconfig, field: lib): JSON.stringify(Object.fromEntries(vmService.cloudConfigMap)) } result += '}'; return result; } + +export function mapToJson(map: Map, jsonString: string): string { + let isfirstElement = true + map.forEach((value, key) => { + if(!isfirstElement) { + jsonString += ',' + } + if(typeof value === 'string' || Array.isArray(value)) { + jsonString += '"' + key + '": ' + JSON.stringify(value) + ' '; + } else if (value instanceof Map){ + jsonString += '"' + key + '": {' + mapToJson(value, '') + '} '; + } else { + jsonString += '"' + key + '": {' + mapToJson(new Map(Object.entries(value)), '') + '} '; + } + isfirstElement = false + }); + return jsonString +}