Repository: config4k/config4k
Pull request #110 (2022-03-30 09:58:02)

allow private access with getConfigMap
regarding issue #109 allow `toConfig` to work with private classes

codecov[bot]: # [Codecov](https://codecov.io/gh/config4k/config4k/pull/110?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k) Report
> Merging [#110](https://codecov.io/gh/config4k/config4k/pull/110?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k) (82760c2) into [main](https://codecov.io/gh/config4k/config4k/commit/896df74f1d6a0d8521e74e4304154fa1ffd90403?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k) (896df74) will **increase** coverage by `0.06%`.
> The diff coverage is `50.00%`.

```diff
@@             Coverage Diff              @@
##               main     #110      +/-   ##
============================================
+ Coverage     88.58%   88.64%   +0.06%     
  Complexity       55       55              
============================================
  Files            30       30              
  Lines           184      185       +1     
  Branches         69       69              
============================================
+ Hits            163      164       +1     
  Misses            9        9              
  Partials         12       12              
```


| [Impacted Files](https://codecov.io/gh/config4k/config4k/pull/110?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k) | Coverage Δ | |
|---|---|---|
| [src/main/kotlin/io/github/config4k/GetConfigMap.kt](https://codecov.io/gh/config4k/config4k/pull/110/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k#diff-c3JjL21haW4va290bGluL2lvL2dpdGh1Yi9jb25maWc0ay9HZXRDb25maWdNYXAua3Q=) | `91.66% <50.00%> (+0.75%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=config4k)


Patch:
diff --git a/src/main/kotlin/io/github/config4k/GetConfigMap.kt b/src/main/kotlin/io/github/config4k/GetConfigMap.kt
index fc6220a..e9944ca 100644
--- a/src/main/kotlin/io/github/config4k/GetConfigMap.kt
+++ b/src/main/kotlin/io/github/config4k/GetConfigMap.kt
@@ -4,6 +4,7 @@ import com.typesafe.config.ConfigValue
 import kotlin.reflect.KClass
 import kotlin.reflect.full.memberProperties
 import kotlin.reflect.full.primaryConstructor
+import kotlin.reflect.jvm.isAccessible
 
 internal fun getConfigMap(
     receiver: Any,
@@ -12,7 +13,8 @@ internal fun getConfigMap(
     clazz.primaryConstructor!!.parameters.mapNotNull {
         val parameterName = it.name!!
         clazz.memberProperties
-            .find { it.name == parameterName }!!
+            .find { member -> member.name == parameterName }!!
+            .apply { isAccessible = true }
             .get(receiver)
             ?.let { parameterValue ->
                 parameterName to parameterValue.toConfigValue()


Test patch:
diff --git a/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt b/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
index db6adb8..d2a6522 100644
--- a/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
+++ b/src/test/kotlin/io/github/config4k/TestToConfigForArbitraryType.kt
@@ -39,6 +39,15 @@ class TestToConfigForArbitraryType : WordSpec({
             person.extract<Size>("size") shouldBe Size.SMALL
         }
     }
+
+    "PrivatePerson.toConfig" should {
+        "return Config having Person" {
+            val person = PrivatePerson("foo", 20).toConfig("person")
+            person.extract<PrivatePerson>("person") shouldBe PrivatePerson("foo", 20)
+        }
+    }
 })
 
 data class NullableName(val name: String?)
+
+private data class PrivatePerson(val name: String, val age: Int? = 10)