Skip to content

Commit

Permalink
KTOR-1264 Add java.util.UUID to jvm conversion (#2188)
Browse files Browse the repository at this point in the history
Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
  • Loading branch information
hfhbd and hfhbd authored Sep 7, 2021
1 parent 4c5a2f6 commit 142c141
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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)
}
}

0 comments on commit 142c141

Please sign in to comment.