diff --git a/exposed-core/api/exposed-core.api b/exposed-core/api/exposed-core.api index eb1ec65ab5..98772f030e 100644 --- a/exposed-core/api/exposed-core.api +++ b/exposed-core/api/exposed-core.api @@ -533,6 +533,7 @@ public class org/jetbrains/exposed/sql/ColumnWithTransform : org/jetbrains/expos public fun nonNullValueToString (Ljava/lang/Object;)Ljava/lang/String; public fun notNullValueToDB (Ljava/lang/Object;)Ljava/lang/Object; public fun setNullable (Z)V + public fun setParameter (Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;ILjava/lang/Object;)V public fun sqlType ()Ljava/lang/String; public fun unwrap (Ljava/lang/Object;)Ljava/lang/Object; public final fun unwrapRecursive (Ljava/lang/Object;)Ljava/lang/Object; diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index 7034a53702..f4bfaa8200 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -324,6 +324,10 @@ open class ColumnWithTransform( } override var nullable = delegate.nullable + + override fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) { + return delegate.setParameter(stmt, index, value) + } } // Numeric columns diff --git a/exposed-json/src/test/kotlin/org/jetbrains/exposed/sql/json/JsonColumnTests.kt b/exposed-json/src/test/kotlin/org/jetbrains/exposed/sql/json/JsonColumnTests.kt index 21fe50c64a..b47be2a04c 100644 --- a/exposed-json/src/test/kotlin/org/jetbrains/exposed/sql/json/JsonColumnTests.kt +++ b/exposed-json/src/test/kotlin/org/jetbrains/exposed/sql/json/JsonColumnTests.kt @@ -406,4 +406,23 @@ class JsonColumnTests : DatabaseTestsBase() { assertEquals(newData2, newResult?.get(tester.jsonColumn)) } } + + @Test + fun testJsonWithTransformer() { + val tester = object : Table("tester") { + val numbers: Column = json("numbers", Json.Default).transform( + wrap = { DoubleArray(it.size) { i -> 1.0 * it[i] } }, + unwrap = { IntArray(it.size) { i -> it[i].toInt() } } + ) + } + + withTables(tester) { + val data = doubleArrayOf(1.0, 2.0, 3.0) + tester.insert { + it[numbers] = data + } + + assertContentEquals(data, tester.selectAll().single()[tester.numbers]) + } + } }