com.fasterxml.jackson.module.kotlin.KotlinBeanDeserializerModifier.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-kotlin Show documentation
Show all versions of jackson-module-kotlin Show documentation
Add-on module for Jackson (https://github.com/FasterXML/jackson/) to support
Kotlin language, specifically introspection of method/constructor parameter names,
without having to add explicit property name annotation.
package com.fasterxml.jackson.module.kotlin
import com.fasterxml.jackson.databind.BeanDescription
import com.fasterxml.jackson.databind.DeserializationConfig
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier
// [module-kotlin#225]: keep Kotlin singletons as singletons
object KotlinBeanDeserializerModifier : BeanDeserializerModifier() {
override fun modifyDeserializer(
config: DeserializationConfig,
beanDesc: BeanDescription,
deserializer: JsonDeserializer<*>
): JsonDeserializer {
val modifiedFromParent = super.modifyDeserializer(config, beanDesc, deserializer)
val objectSingletonInstance = objectSingletonInstance(beanDesc.beanClass)
return if (objectSingletonInstance != null) {
KotlinObjectSingletonDeserializer(objectSingletonInstance, modifiedFromParent)
} else {
modifiedFromParent
}
}
}
private fun objectSingletonInstance(beanClass: Class<*>): Any? = if (!beanClass.isKotlinClass()) {
null
} else {
beanClass.kotlin.objectInstance
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy