Skip to content

Commit

Permalink
Making the code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan-lt committed Oct 6, 2019
1 parent e8f4f81 commit f7f9171
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ object KotlinBeanDeserializerModifier: BeanDeserializerModifier() {
config: DeserializationConfig,
beanDesc: BeanDescription,
deserializer: JsonDeserializer<*>
) = super.modifyDeserializer(config, beanDesc, deserializer)
.maybeSingletonDeserializer(objectSingletonInstance(beanDesc.beanClass))
}
): JsonDeserializer<out Any> {
val modifiedFromParent = super.modifyDeserializer(config, beanDesc, deserializer)

val objectSingletonInstance = objectSingletonInstance(beanDesc.beanClass)

fun JsonDeserializer<*>.maybeSingletonDeserializer(singleton: Any?) = when (singleton) {
null -> this
else -> this.asSingletonDeserializer(singleton)
return if (objectSingletonInstance != null) {
KotlinObjectSingletonDeserializer(objectSingletonInstance, modifiedFromParent)
} else {
modifiedFromParent
}
}
}

private fun objectSingletonInstance(beanClass: Class<*>): Any? = if (!beanClass.isKotlinClass()) {
null
} else {
beanClass.kotlin.objectInstance
}
}

0 comments on commit f7f9171

Please sign in to comment.