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

Commit ce12167

Browse files
committed
creatorの取り方の変化に合わせ修正
1 parent 49af7c8 commit ce12167

File tree

1 file changed

+4
-1
lines changed
  • src/main/kotlin/com/wrongwrong/mapk/core

1 file changed

+4
-1
lines changed

src/main/kotlin/com/wrongwrong/mapk/core/Mapper.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ private fun Collection<KProperty1<*, *>>.filterTargets(): Collection<KProperty1<
9595

9696
private fun mapObject(param: ParameterForMap, value: Any): Any? {
9797
val valueClazz: KClass<*> = value::class
98+
val creator: ((Any) -> Any?)? by lazy {
99+
param.getCreator(valueClazz)
100+
}
98101

99102
return when {
100103
// パラメータに対してvalueが代入可能(同じもしくは親クラス)であればそのまま用いる
101104
param.clazz.isSuperclassOf(valueClazz) -> value
102105
// creatorに一致する組み合わせが有れば設定されていればそれを使う
103-
param.creatorMap.contains(valueClazz) -> param.creatorMap.getValue(valueClazz)(value)
106+
creator != null -> creator!!(value)
104107
// 要求された値がenumかつ元が文字列ならenum mapperでマップ
105108
param.javaClazz.isEnum && value is String -> EnumMapper.getEnum(param.clazz.java, value)
106109
// 要求されているパラメータがStringならtoStringする

0 commit comments

Comments
 (0)