From c3a9591516b0683a521d6dc4211fb5daa98db581 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 25 Aug 2025 11:16:31 +0200 Subject: [PATCH 1/2] Fix null values in CRUD entries reported as strings --- CHANGELOG.md | 1 + .../commonIntegrationTest/kotlin/com/powersync/CrudTest.kt | 4 ++++ .../kotlin/com/powersync/db/crud/SerializedRow.kt | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 688a54d6..6ef0ecca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ to upload multiple transactions in a batch. * Fix modifying severity of the global Kermit logger * Add `PowerSync` tag for the logs +* Fix `null` values in CRUD entries being reported as `"null"` strings. * [INTERNAL] Added helpers for Swift read and write lock exception handling. ## 1.4.0 diff --git a/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt b/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt index 4ba15d9b..b6ed73bb 100644 --- a/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt +++ b/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt @@ -134,6 +134,10 @@ class CrudTest { ) batch.crud[0].previousValues shouldBe null + batch.crud[1].opData shouldBe mapOf( + "a" to "te\"xt", + "b" to null, + ) batch.crud[1].opData?.typed shouldBe mapOf( "a" to "te\"xt", diff --git a/core/src/commonMain/kotlin/com/powersync/db/crud/SerializedRow.kt b/core/src/commonMain/kotlin/com/powersync/db/crud/SerializedRow.kt index 38499c8e..43e7e127 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/crud/SerializedRow.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/crud/SerializedRow.kt @@ -4,6 +4,7 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.jsonPrimitive import kotlin.experimental.ExperimentalObjCRefinement import kotlin.native.HiddenFromObjC @@ -47,11 +48,11 @@ internal class SerializedRow( private data class ToStringEntry( val inner: Map.Entry, -) : Map.Entry { +) : Map.Entry { override val key: String get() = inner.key - override val value: String - get() = inner.value.jsonPrimitive.content + override val value: String? + get() = inner.value.jsonPrimitive.contentOrNull } private class TypedRow( From 5a1742d204b5ec46135db8bc7c16156e5d9c73e2 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 25 Aug 2025 11:26:39 +0200 Subject: [PATCH 2/2] Reformat --- .../kotlin/com/powersync/CrudTest.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt b/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt index b6ed73bb..566a2ae6 100644 --- a/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt +++ b/core/src/commonIntegrationTest/kotlin/com/powersync/CrudTest.kt @@ -134,10 +134,11 @@ class CrudTest { ) batch.crud[0].previousValues shouldBe null - batch.crud[1].opData shouldBe mapOf( - "a" to "te\"xt", - "b" to null, - ) + batch.crud[1].opData shouldBe + mapOf( + "a" to "te\"xt", + "b" to null, + ) batch.crud[1].opData?.typed shouldBe mapOf( "a" to "te\"xt",