@@ -45,7 +45,7 @@ class KMapper<T: Any>(private val function: KFunction<T>, propertyNameConverter:
4545 fun map (src : Any ): T {
4646 val srcMap: Map <String , KProperty1 .Getter <* , * >> =
4747 src::class .memberProperties.filterTargets().associate { property ->
48- val getter = property.getter
48+ val getter = property.getAccessibleGetter()
4949
5050 val key = getter.annotations
5151 .find { it is KPropertyAlias }
@@ -73,7 +73,7 @@ class KMapper<T: Any>(private val function: KFunction<T>, propertyNameConverter:
7373 is Pair <* , * > -> mapOf (arg.first as String to { arg.second })
7474 else -> {
7575 arg::class .memberProperties.filterTargets().associate { property ->
76- val getter = property.getter
76+ val getter = property.getAccessibleGetter()
7777
7878 val key = getter.annotations
7979 .find { it is KPropertyAlias }
@@ -103,6 +103,12 @@ private fun Collection<KProperty1<*, *>>.filterTargets(): Collection<KProperty1<
103103 }
104104}
105105
106+ private fun KProperty1 <* , * >.getAccessibleGetter (): KProperty1 .Getter <* , * > {
107+ // アクセス制限の有るクラスではpublicなプロパティでもゲッターにアクセスできない場合が有るため、アクセス可能にして使う
108+ getter.isAccessible = true
109+ return getter
110+ }
111+
106112private fun <T : Any > getTarget (clazz : KClass <T >): KFunction <T > {
107113 val constructors: List <KFunction <T >> = clazz.constructors
108114 .filter { it.annotations.any { annotation -> annotation is KConstructor } }
0 commit comments