Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 6cbcfca

Browse files
committed
コンバータのサポートを追加
1 parent 18b16ba commit 6cbcfca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/kotlin/com/mapk/kmapper/BoundParameterForMap.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@ internal class BoundParameterForMap<S : Any>(val param: KParameter, property: KP
2121
val paramClazz = param.type.classifier as KClass<*>
2222
val propertyClazz = property.returnType.classifier as KClass<*>
2323

24-
// TODO: コンバータへの対応
24+
val converter = (convertersFromConstructors(paramClazz) +
25+
convertersFromStaticMethods(paramClazz) +
26+
convertersFromCompanionObject(paramClazz))
27+
.filter { (key, _) -> propertyClazz.isSubclassOf(key) }
28+
.let {
29+
if (1 < it.size) throw IllegalArgumentException("${param.name} has multiple converter. $it")
30+
31+
it.singleOrNull()?.second
32+
}
33+
2534
map = when {
35+
converter != null -> { { converter.call(propertyGetter.invoke(it)) } }
2636
paramClazz.isSubclassOf(propertyClazz) -> { { propertyGetter.invoke(it) } }
2737
paramClazz.java.isEnum && propertyClazz == String::class -> { {
2838
EnumMapper.getEnum(paramClazz.java, propertyGetter.invoke(it) as String)

0 commit comments

Comments
 (0)