You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a scenario where we try to deserialize a @SqlJsonValue to a nullable field, where the database row contains the jsonb value 'null', (i.e. not SQL-null but json-null), the deserialization process crashes.
data classNullableExample(valid:Int, @SqlJsonValue valvalue:MyPersonJson?)
Sql("""INSERT INTO JsonbExample (id, value) VALUES (1, 'null')""").action().runOn(ctx)
Sql("SELECT id, value FROM JsonbExample").queryOf<NullableExample>().runOn(ctx)
Unexpected JSON token at offset 0: Expected start of the object '{', but had 'n' instead at path: $
JSON input: null
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected start of the object '{', but had 'n' instead at path: $
JSON input: null
It appears that in RowDecoder, after validNullOrElse check the result is passed to the decoder; however at some point in the call stack the nullability of the target type is lost.
A minimal example of what is happening at kotlinx.serialization level:
Json.decodeFromString<JsonSpecData.A.MyPerson?>("null") shouldBe null// okJson.decodeFromString<JsonSpecData.A.MyPerson>("null") shouldBe null// exception as above
I was unable to figure out where this happens, so no fix is included - however a branch with a test for this case can be found here: main...arvearve:terpal-sql:json-nullable
The text was updated successfully, but these errors were encountered:
In a scenario where we try to deserialize a
@SqlJsonValue
to a nullable field, where the database row contains the jsonb value'null'
, (i.e. not SQL-null but json-null), the deserialization process crashes.It appears that in
RowDecoder
, aftervalidNullOrElse
check the result is passed to the decoder; however at some point in the call stack the nullability of the target type is lost.A minimal example of what is happening at kotlinx.serialization level:
I was unable to figure out where this happens, so no fix is included - however a branch with a test for this case can be found here:
main...arvearve:terpal-sql:json-nullable
The text was updated successfully, but these errors were encountered: