From f7f9171a320e644decf2fe90cb93ebc4f0f4457b Mon Sep 17 00:00:00 2001 From: Lukas Krecan Date: Sun, 6 Oct 2019 09:45:52 +0200 Subject: [PATCH] Making the code more readable --- .../kotlin/KotlinBeanDeserializerModifier.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinBeanDeserializerModifier.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinBeanDeserializerModifier.kt index eaf42716..28c782f2 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinBeanDeserializerModifier.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinBeanDeserializerModifier.kt @@ -10,17 +10,21 @@ object KotlinBeanDeserializerModifier: BeanDeserializerModifier() { config: DeserializationConfig, beanDesc: BeanDescription, deserializer: JsonDeserializer<*> - ) = super.modifyDeserializer(config, beanDesc, deserializer) - .maybeSingletonDeserializer(objectSingletonInstance(beanDesc.beanClass)) -} + ): JsonDeserializer { + 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 -} \ No newline at end of file +}