<@U01SP2GJYAU> Do DataTypeConverters automatically...
# komapper
d
@Toshihiro Nakamura Do DataTypeConverters automatically handle nullable fields, or do I need to include the logic in the converter?
I tried doing this:
Copy code
class JsonElementTypeConverter : DataTypeConverter<JsonElement, String> {
    override val exteriorClass: KClass<JsonElement> = JsonElement::class
    override val interiorClass: KClass<String> = String::class

    override fun unwrap(exterior: JsonElement): String {
        return Json.decodeFromJsonElement(exterior)
    }

    override fun wrap(interior: String): JsonElement {
        return Json.encodeToJsonElement(interior)
    }
}
But it gives me the error:
Copy code
Index -1 out of bounds for length 0
java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.remove(ArrayList.java:536)
	at kotlinx.serialization.internal.TaggedDecoder.popTag(Tagged.kt:322)
	at kotlinx.serialization.internal.TaggedDecoder.decodeString(Tagged.kt:232)
	at kotlinx.serialization.internal.StringSerializer.deserialize(Primitives.kt:161)
	at kotlinx.serialization.internal.StringSerializer.deserialize(Primitives.kt:157)
	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:61)
	at kotlinx.serialization.json.internal.AbstractJsonTreeDecoder.decodeSerializableValue(TreeJsonDecoder.kt:52)
	at kotlinx.serialization.json.internal.TreeJsonDecoderKt.readJson(TreeJsonDecoder.kt:25)
	at kotlinx.serialization.json.Json.decodeFromJsonElement(Json.kt:127)
	at com....utils.JsonElementTypeConverter.unwrap(KomapperTypes.kt:23)
	at com....utils.JsonElementTypeConverter.unwrap(KomapperTypes.kt:11)
	at org.komapper.r2dbc.R2dbcDataTypeProxy.setValue(R2dbcDataType.kt:533)
The
JsonElement
field in my entity is nullable...
Wait, it could be my fault here...
No, I just used the wrong functions from KotlinX Serialization..., it's still not a case of when it's null.
t
do I need to include the logic in the converter?
No, you don’t. A null value is processed prior to the execution of DataTypeConverter.