diff options
author | 2019-06-18 13:13:50 -0400 | |
---|---|---|
committer | 2019-06-18 13:13:50 -0400 | |
commit | 091bba704d8e9137b9bca9ed02d139539aa2ac53 (patch) | |
tree | b21fe4f592c3a5a67d881c21cc3a5e92b667ed03 | |
parent | da79303b367ed5d4f12a279a401dee379f38147e (diff) |
Fix wrong mapping of json to map
This is causing jinja2 template rendering to be missing the nested
element under a complex type within the json string.
Change-Id: I607ee5ed8579a461a29b991e2bc77857048755d1
Issue-ID: CCSDK-1414
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
-rw-r--r-- | ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt index 912667e0a..1dbbd9977 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service +import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.hubspot.jinjava.Jinjava @@ -23,11 +24,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintJsonNodeFactory import org.onap.ccsdk.cds.controllerblueprints.core.removeNullNode - object BluePrintJinjaTemplateService { fun generateContent(template: String, json: String, ignoreJsonNull: Boolean, - additionalContext: MutableMap<String, Any>): String { + additionalContext: MutableMap<String, Any>): String { + // Load template val jinJava = Jinjava() val mapper = ObjectMapper() @@ -37,15 +38,16 @@ object BluePrintJinjaTemplateService { // Add the JSON Data to the context if (json.isNotEmpty()) { val jsonNode = mapper.readValue<JsonNode>(json, JsonNode::class.java) - ?: throw BluePrintProcessorException("couldn't get json node from json") - if (ignoreJsonNull) + ?: throw BluePrintProcessorException("couldn't get json node from json") + if (ignoreJsonNull) { jsonNode.removeNullNode() - jsonNode.fields().forEach { entry -> - additionalContext[entry.key] = entry.value } + + val jsonMap: Map<String, Any> = mapper.readValue(json, object : TypeReference<Map<String, Any>>() {}) + additionalContext.putAll(jsonMap) } - return jinJava.render(template, additionalContext.toMap()) + return jinJava.render(template, additionalContext) } } |