Repository: config4k/config4k (kotlin)

Issue:
Support `java.util.UUID`

Pull request:
Fixes #85

Patch:
diff --git a/docs/supported-types.md b/docs/supported-types.md
index ab887ea..e8f566c 100644
--- a/docs/supported-types.md
+++ b/docs/supported-types.md
@@ -18,6 +18,7 @@ Property delegation, `extract` and `toConfig` support these types:
 - `java.time.Duration`
 - `java.time.Period`
 - `java.time.temporal.TemporalAmount`
+- `java.util.UUID`
 - `kotlin.text.Regex`
 - Collections
     - `List`
diff --git a/src/main/kotlin/io/github/config4k/Extension.kt b/src/main/kotlin/io/github/config4k/Extension.kt
index 46f96d0..defe908 100644
--- a/src/main/kotlin/io/github/config4k/Extension.kt
+++ b/src/main/kotlin/io/github/config4k/Extension.kt
@@ -6,6 +6,7 @@ import com.typesafe.config.ConfigFactory
 import io.github.config4k.readers.SelectReader
 import java.io.File
 import java.nio.file.Path
+import java.util.UUID
 import kotlin.reflect.KProperty
 import kotlin.reflect.full.primaryConstructor
 
@@ -88,6 +89,7 @@ public fun Any.toConfig(name: String): Config {
         this is Enum<*> -> mapOf(name to this.name)
         this is File -> mapOf(name to this.toString())
         this is Path -> mapOf(name to this.toString())
+        this is UUID -> mapOf(name to this.toString())
         this is Iterable<*> -> {
             val list = this.map {
                 it?.toConfigValue()?.unwrapped()
diff --git a/src/main/kotlin/io/github/config4k/readers/SelectReader.kt b/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
index b25114c..b97c075 100644
--- a/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
+++ b/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
@@ -12,6 +12,7 @@ import java.nio.file.Path
 import java.time.Duration
 import java.time.Period
 import java.time.temporal.TemporalAmount
+import java.util.UUID
 import kotlin.reflect.full.primaryConstructor
 
 /**
@@ -44,6 +45,7 @@ public object SelectReader {
             Period::class -> PeriodReader()
             TemporalAmount::class -> TemporalAmountReader()
             ConfigMemorySize::class -> MemorySizeReader()
+            UUID::class -> UUIDReader()
             Config::class -> ConfigReader()
             ConfigValue::class -> ConfigValueReader()
             MutableList::class -> ListReader(clazz.typeArguments.getValue("E"), mutable = true)
diff --git a/src/main/kotlin/io/github/config4k/readers/UUIDReader.kt b/src/main/kotlin/io/github/config4k/readers/UUIDReader.kt
new file mode 100644
index 0000000..9f9f47c
--- /dev/null
+++ b/src/main/kotlin/io/github/config4k/readers/UUIDReader.kt
@@ -0,0 +1,5 @@
+package io.github.config4k.readers
+
+import java.util.UUID
+
+internal class UUIDReader : Reader<UUID>({ config, path -> UUID.fromString(config.getString(path)) })


Test patch:
diff --git a/src/test/kotlin/io/github/config4k/TestArbitraryType.kt b/src/test/kotlin/io/github/config4k/TestArbitraryType.kt
index eea8ca5..7ee4906 100644
--- a/src/test/kotlin/io/github/config4k/TestArbitraryType.kt
+++ b/src/test/kotlin/io/github/config4k/TestArbitraryType.kt
@@ -2,6 +2,7 @@ package io.github.config4k
 
 import io.kotest.core.spec.style.WordSpec
 import io.kotest.matchers.shouldBe
+import java.util.UUID
 
 class TestArbitraryType : WordSpec({
     "Config.extract<Person>" should {
@@ -122,6 +123,18 @@ class TestArbitraryType : WordSpec({
             nestJavaBean.person2 shouldBe null
         }
     }
+
+    "Config.extract<DataWithUUID>()" should {
+        "return DataWithUUID" {
+            val config =
+                """
+                {
+                  uuid = 3f5f1d2f-38b7-4a14-9e67-c618d8f83189
+                }""".toConfig()
+            val data = config.extract<DataWithUUID>()
+            data shouldBe DataWithUUID(UUID.fromString("3f5f1d2f-38b7-4a14-9e67-c618d8f83189"))
+        }
+    }
 })
 
 data class Person(val name: String, val age: Int? = 10)
@@ -134,3 +147,5 @@ data class WholeConfig(val key: Person)
 data class NestHyphenated(val nestedPerson: Person)
 
 data class NestJavaBean(val person: TestJavaBean, val person2: TestJavaBean?)
+
+data class DataWithUUID(val uuid: UUID)
diff --git a/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt b/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
index d2a6522..de56432 100644
--- a/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
+++ b/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
@@ -2,6 +2,7 @@ package io.github.config4k
 
 import io.kotest.core.spec.style.WordSpec
 import io.kotest.matchers.shouldBe
+import java.util.*
 
 class TestToConfigForArbitraryType : WordSpec({
     "Person.toConfig" should {
@@ -46,6 +47,14 @@ class TestToConfigForArbitraryType : WordSpec({
             person.extract<PrivatePerson>("person") shouldBe PrivatePerson("foo", 20)
         }
     }
+
+    "DataWithUUID.toConfig" should {
+        "return Config having DataWithUUID" {
+            val data = DataWithUUID(UUID.fromString("3f5f1d2f-38b7-4a14-9e67-c618d8f83189"))
+            val config = data.toConfig("data")
+            config.extract<DataWithUUID>("data") shouldBe data
+        }
+    }
 })
 
 data class NullableName(val name: String?)