Refactoring ResourceAssignmentUtils
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / CustomFunctions.kt
index 08bc6c3..1aaf9d8 100644 (file)
@@ -54,6 +54,10 @@ fun String.asJsonPrimitive(): TextNode {
     return TextNode(this)
 }
 
+inline fun <reified T : Any> String.jsonAsType(): T {
+    return JacksonUtils.readValue<T>(this.trim())
+}
+
 // If you know the string is json content, then use the function directly
 fun String.jsonAsJsonType(): JsonNode {
     return JacksonUtils.jsonNode(this.trim())
@@ -171,7 +175,7 @@ fun ArrayNode.asListOfString(): List<String> {
 
 fun <T> JsonNode.asType(clazzType: Class<T>): T {
     return JacksonUtils.readValue(this, clazzType)
-            ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType")
+        ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType")
 }
 
 fun JsonNode.asListOfString(): List<String> {
@@ -179,20 +183,17 @@ fun JsonNode.asListOfString(): List<String> {
     return this.asListOfString()
 }
 
-fun JsonNode.returnNullIfMissing(): JsonNode? {
-    return if (this is NullNode || this is MissingNode) {
+fun <T : JsonNode> T?.returnNullIfMissing(): JsonNode? {
+    return if (this == null || this is NullNode || this is MissingNode) {
         null
-    } else this
+    }
+    else this
 }
 
-fun <T : JsonNode> T?.isNull(): Boolean {
+fun <T : JsonNode> T?.isNullOrMissing(): Boolean {
     return this == null || this is NullNode || this is MissingNode
 }
 
-fun <T : JsonNode> T?.isNotNull(): Boolean {
-    return !(this == null || this is NullNode || this is MissingNode)
-}
-
 /**
  * Convert Json to map of json node, the root fields will be map keys
  */