Skip to content

Commit

Permalink
fix: json DB reading failing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFruxz committed Jan 17, 2023
1 parent 9133759 commit 64e3152
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class DynamicJsonColumnType<T : Any>(private val type: KType) : ColumnType() {
override fun nonNullValueToString(value: Any): String =
value.toJsonString()

override fun valueFromDB(value: Any): T =
jsonBase.decodeFromString(jsonBase.serializersModule.serializer(type), "$value").forceCast()
override fun valueFromDB(value: Any): T = when (value) {
is String -> jsonBase.decodeFromString(jsonBase.serializersModule.serializer(type), "$value").forceCast()
else -> value.forceCast()
}

override fun notNullValueToDB(value: Any): String =
jsonBase.encodeToString(jsonBase.serializersModule.serializer(type), value.forceCastOrNull<T?>())
Expand Down

0 comments on commit 64e3152

Please sign in to comment.