diff --git a/ktor-utils/jvm/src/io/ktor/util/converters/ConversionServiceJvm.kt b/ktor-utils/jvm/src/io/ktor/util/converters/ConversionServiceJvm.kt index e56ab5806ee..51a9507d018 100644 --- a/ktor-utils/jvm/src/io/ktor/util/converters/ConversionServiceJvm.kt +++ b/ktor-utils/jvm/src/io/ktor/util/converters/ConversionServiceJvm.kt @@ -5,6 +5,7 @@ package io.ktor.util.converters import java.math.* +import java.util.* import kotlin.reflect.* @OptIn(ExperimentalStdlibApi::class) @@ -34,6 +35,7 @@ private fun convertSimpleTypes(value: String, klass: KClass<*>): Any? = when (kl java.lang.Character::class -> value[0] BigDecimal::class -> BigDecimal(value) BigInteger::class -> BigInteger(value) + UUID::class -> UUID.fromString(value) else -> null } @@ -53,6 +55,7 @@ internal actual fun platformDefaultToValues(value: Any): List? { is java.lang.Character -> listOf(value.toString()) is BigDecimal -> listOf(value.toString()) is BigInteger -> listOf(value.toString()) + is UUID -> listOf(value.toString()) else -> null } } diff --git a/ktor-utils/jvm/test/io/ktor/tests/utils/converters/DataConversionTest.kt b/ktor-utils/jvm/test/io/ktor/tests/utils/converters/DataConversionTest.kt index 65ad30607b8..f1f559d20f1 100644 --- a/ktor-utils/jvm/test/io/ktor/tests/utils/converters/DataConversionTest.kt +++ b/ktor-utils/jvm/test/io/ktor/tests/utils/converters/DataConversionTest.kt @@ -7,6 +7,7 @@ package io.ktor.tests.utils.converters import io.ktor.util.converters.* import io.ktor.util.reflect.* import java.math.* +import java.util.* import kotlin.test.* class DataConversionTest { @@ -56,4 +57,14 @@ class DataConversionTest { val toValues = DefaultConversionService.toValues(converted) assertEquals(listOf("B"), toValues) } + + @Test + fun testDefaultConversionUUID() { + val id = UUID.randomUUID() + val converted = DefaultConversionService.fromValues(listOf(id.toString()), typeInfo()) + assertEquals(id, converted) + + val toValues = DefaultConversionService.toValues(converted) + assertEquals(listOf(id.toString()), toValues) + } }