Enabling Code Formatter
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / utils / JacksonUtils.kt
index 945f300..ace66cf 100644 (file)
@@ -85,7 +85,8 @@ class JacksonUtils {
                 withContext(Dispatchers.Default) {
                     IOUtils.toString(
                         JacksonUtils::class.java.classLoader
-                            .getResourceAsStream(fileName), Charset.defaultCharset()
+                            .getResourceAsStream(fileName),
+                        Charset.defaultCharset()
                     )
                 }
             }
@@ -133,9 +134,13 @@ class JacksonUtils {
             return getJson(wrapperMap, pretty)
         }
 
-        fun getJson(any: kotlin.Any, pretty: Boolean = false): String {
+        fun getJson(any: kotlin.Any, pretty: Boolean = false, includeNull: Boolean = false): String {
             val objectMapper = jacksonObjectMapper()
-            objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
+            if (includeNull) {
+                objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS)
+            } else {
+                objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
+            }
             if (pretty) {
                 objectMapper.enable(SerializationFeature.INDENT_OUTPUT)
             }
@@ -225,7 +230,6 @@ class JacksonUtils {
         fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean {
             return when (type.toLowerCase()) {
                 BluePrintConstants.DATA_TYPE_LIST -> jsonNode.isArray
-                BluePrintConstants.DATA_TYPE_MAP -> jsonNode.isContainerNode
                 else -> false
             }
         }
@@ -283,7 +287,7 @@ class JacksonUtils {
         fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) {
             val defaultValue = getDefaultValueOfPrimitiveAsJsonNode(primitiveType)
                 ?: throw BluePrintException("populatePrimitiveDefaultValues expected only primitive values! Received type ($primitiveType)")
-            objectNode.set(key, defaultValue)
+            objectNode.set<JsonNode>(key, defaultValue)
         }
 
         fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) {
@@ -305,11 +309,11 @@ class JacksonUtils {
 
         fun populateJsonNodeValues(key: String, nodeValue: JsonNode?, type: String, objectNode: ObjectNode) {
             if (nodeValue == null || nodeValue is NullNode) {
-                objectNode.set(key, nodeValue)
+                objectNode.set<JsonNode>(key, nodeValue)
             } else if (BluePrintTypes.validPrimitiveTypes().contains(type)) {
                 populatePrimitiveValues(key, nodeValue, type, objectNode)
             } else {
-                objectNode.set(key, nodeValue)
+                objectNode.set<JsonNode>(key, nodeValue)
             }
         }