From dd0b7cb7e44c658b91e67be143e5faebf4d0574c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Kristian=20Haaland-S=C3=B8rensen?= Date: Tue, 3 Sep 2024 15:29:44 +0200 Subject: [PATCH] fix json column being saved as a stringified Kotlin object --- .../monta/ocpp/emulator/common/util/JsonColumnType.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/jvmMain/kotlin/com/monta/ocpp/emulator/common/util/JsonColumnType.kt b/common/src/jvmMain/kotlin/com/monta/ocpp/emulator/common/util/JsonColumnType.kt index 6021b93..0cfe840 100644 --- a/common/src/jvmMain/kotlin/com/monta/ocpp/emulator/common/util/JsonColumnType.kt +++ b/common/src/jvmMain/kotlin/com/monta/ocpp/emulator/common/util/JsonColumnType.kt @@ -50,7 +50,7 @@ class JsonColumnType( @Suppress("UNCHECKED_CAST") override fun valueFromDB(value: Any): T { return when (value) { - is ByteArray -> parse(String(value).unescapeSqlJsonString()) + is ByteArray -> parse(value.decodeToString().unescapeSqlJsonString()) else -> value as T } } @@ -69,6 +69,13 @@ class JsonColumnType( value } } + + override fun notNullValueToDB(value: T): Any = stringify(value) + + override fun valueToString(value: T?): String = when (value) { + is Iterable<*> -> nonNullValueToString(value) + else -> super.valueToString(value) + } } /**