Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-1264 - Add UUID to DefaultConversionService #2188

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.ktor.util.converters

import java.math.*
import java.util.*
import kotlin.reflect.*

@OptIn(ExperimentalStdlibApi::class)
Expand Down Expand Up @@ -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
}

Expand All @@ -53,6 +55,7 @@ internal actual fun platformDefaultToValues(value: Any): List<String>? {
is java.lang.Character -> listOf(value.toString())
is BigDecimal -> listOf(value.toString())
is BigInteger -> listOf(value.toString())
is UUID -> listOf(value.toString())
else -> null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<UUID>())
assertEquals(id, converted)

val toValues = DefaultConversionService.toValues(converted)
assertEquals(listOf(id.toString()), toValues)
}
}