Repository: config4k/config4k (kotlin)

Issue:
Feature request: Support java.net.URL
**Is your feature request related to a problem? Please describe.**
I want to extract url's from my config

**Describe the solution you'd like**
Add an URLReader to https://github.com/config4k/config4k/blob/master/src/main/io.github.config4k/readers/SelectReader.kt

Pull request description:
Fixes #88

Patch:
diff --git a/docs/supported-types.md b/docs/supported-types.md
index e8f566c..7b819ab 100644
--- a/docs/supported-types.md
+++ b/docs/supported-types.md
@@ -19,6 +19,7 @@ Property delegation, `extract` and `toConfig` support these types:
 - `java.time.Period`
 - `java.time.temporal.TemporalAmount`
 - `java.util.UUID`
+- `java.net.URL`
 - `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 e882e0e..89256c7 100644
--- a/src/main/kotlin/io/github/config4k/Extension.kt
+++ b/src/main/kotlin/io/github/config4k/Extension.kt
@@ -5,6 +5,7 @@ import com.typesafe.config.ConfigException
 import com.typesafe.config.ConfigFactory
 import io.github.config4k.readers.SelectReader
 import java.io.File
+import java.net.URL
 import java.nio.file.Path
 import java.time.Duration
 import java.util.UUID
@@ -91,6 +92,7 @@ public fun Any.toConfig(name: String): Config {
         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 URL -> mapOf(name to this.toString())
         this is Duration -> mapOf(name to if (this.nano == 0) "${this.seconds} s" else "${this.toNanos()} ns")
         this is Iterable<*> -> {
             val list = this.map {
diff --git a/src/main/kotlin/io/github/config4k/readers/SelectReader.kt b/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
index b97c075..e7c85e6 100644
--- a/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
+++ b/src/main/kotlin/io/github/config4k/readers/SelectReader.kt
@@ -8,6 +8,7 @@ import io.github.config4k.ClassContainer
 import io.github.config4k.Config4kException
 import io.github.config4k.customTypeRegistry
 import java.io.File
+import java.net.URL
 import java.nio.file.Path
 import java.time.Duration
 import java.time.Period
@@ -46,6 +47,7 @@ public object SelectReader {
             TemporalAmount::class -> TemporalAmountReader()
             ConfigMemorySize::class -> MemorySizeReader()
             UUID::class -> UUIDReader()
+            URL::class -> URLReader()
             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/URLReader.kt b/src/main/kotlin/io/github/config4k/readers/URLReader.kt
new file mode 100644
index 0000000..55ba15f
--- /dev/null
+++ b/src/main/kotlin/io/github/config4k/readers/URLReader.kt
@@ -0,0 +1,5 @@
+package io.github.config4k.readers
+
+import java.net.URL
+
+internal class URLReader : Reader<URL>({ config, path -> URL(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 f03a3aa..f1dcd70 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.net.URL
 import java.time.Duration
 import java.util.UUID
 
@@ -136,6 +137,19 @@ class TestArbitraryType : WordSpec({
             data shouldBe DataWithUUID(UUID.fromString("3f5f1d2f-38b7-4a14-9e67-c618d8f83189"))
         }
     }
+
+    "Config.extract<DataWithURL>()" should {
+        "return DataWithURL" {
+            val url = "https://config4k.github.io/config4k/"
+            val config =
+                """
+                {
+                  url = "$url"
+                }""".toConfig()
+            val data = config.extract<DataWithURL>()
+            data.url.toString() shouldBe url
+        }
+    }
 })
 
 data class Person(val name: String, val age: Int? = 10)
@@ -152,3 +166,5 @@ data class NestJavaBean(val person: TestJavaBean, val person2: TestJavaBean?)
 data class DataWithUUID(val uuid: UUID)
 
 data class DataWithDuration(val duration: Duration)
+
+data class DataWithURL(val url: URL)
diff --git a/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt b/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
index 9072ebd..2e2b5eb 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.net.URL
 import java.time.Duration
 import java.util.*
 
@@ -57,6 +58,14 @@ class TestToConfigForArbitraryType : WordSpec({
         }
     }
 
+    "DataWithURL.toConfig" should {
+        "return Config having DataWithURL" {
+            val data = DataWithURL(URL("https://config4k.github.io/config4k/"))
+            val config = data.toConfig("data")
+            config.extract<DataWithURL>("data") shouldBe data
+        }
+    }
+
     "DataWithDuration.toConfig" should {
         "return Config having DataWithDuration" {
             val data = DataWithDuration(Duration.ofMinutes(15))