diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-09-12 14:25:32 +0300 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-09-12 14:25:32 +0300 |
commit | 2609cc76f0565466667fff8ae4d0707b94993877 (patch) | |
tree | e52f013baf27979dd8f0eb0d98bf6ff0c2cbb57f /vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt | |
parent | 079dfc9647074f7e40c8b5fe3eac5bd2b50ade0c (diff) |
create JoshworksJacksonObjectMapper and use it everywhere needed
Create class that implement joshworks object mapper that used jackson
object mapper that support kotlin.
Use it instead local anonymous classes where needed
Issue-ID: VID-611
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Change-Id: Ie00dce0ec9b366515c5e40d9f37b9e64a2ceb357
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt index cf532624c..81afe29e0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt +++ b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt @@ -22,9 +22,23 @@ package org.onap.vid.utils import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.apache.commons.lang3.StringUtils.isEmpty inline fun <reified E: Enum<E>> getEnumFromMapOfStrings(map: Map<String, Any>, key:String, defaultValue:E): E { return java.lang.Enum.valueOf(E::class.java, (map.getOrDefault(key, defaultValue.name) as String)) } @JvmField val JACKSON_OBJECT_MAPPER: ObjectMapper = jacksonObjectMapper() + +class JoshworksJacksonObjectMapper: io.joshworks.restclient.http.mapper.ObjectMapper { + override fun writeValue(value: Any?): String? { + return JACKSON_OBJECT_MAPPER.writeValueAsString(value) + } + + override fun <T : Any?> readValue(value: String?, valueType: Class<T>?): T? { + return if (isEmpty(value)) null else JACKSON_OBJECT_MAPPER.readValue(value, valueType) + } +} + +@JvmField val JOSHWORKS_JACKSON_OBJECT_MAPPER: + io.joshworks.restclient.http.mapper.ObjectMapper = JoshworksJacksonObjectMapper() |