diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 6af8dd08e..9734c1109 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -18,6 +18,7 @@ Contributors: # 2.19.0 (not yet released) WrongWrong (@k163377) +* #954: Replace BooleanTriState with OptBoolean * #944: Fixed to use common util for Member accessibility override * #937: Added type match check to read functions diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 0f5bb0191..378d220d9 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,7 @@ Co-maintainers: 2.19.0 (not yet released) +#954: Replaced `OptBoolean` of internal caching with a common implementation. #944: Common util is now used for member accessibility overrides. #937: For `readValue` and other shorthands for `ObjectMapper` deserialization methods, type consistency checks have been added. diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt index b13ae4918..3960deb5e 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt @@ -1,5 +1,6 @@ package com.fasterxml.jackson.module.kotlin +import com.fasterxml.jackson.annotation.OptBoolean import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor import com.fasterxml.jackson.databind.introspect.AnnotatedMember import com.fasterxml.jackson.databind.introspect.AnnotatedMethod @@ -22,32 +23,12 @@ import kotlin.reflect.jvm.kotlinFunction internal class ReflectionCache(reflectionCacheSize: Int) : Serializable { companion object { // Increment is required when properties that use LRUMap are changed. - private const val serialVersionUID = 3L - } - - sealed class BooleanTriState(val value: Boolean?) { - class True : BooleanTriState(true) - class False : BooleanTriState(false) - class Empty : BooleanTriState(null) - - companion object { - private val TRUE = True() - private val FALSE = False() - private val EMPTY = Empty() - - fun fromBoolean(value: Boolean?): BooleanTriState { - return when (value) { - null -> EMPTY - true -> TRUE - false -> FALSE - } - } - } + private const val serialVersionUID = 4L } private val javaExecutableToKotlin = LRUMap>(reflectionCacheSize, reflectionCacheSize) private val javaExecutableToValueCreator = LRUMap>(reflectionCacheSize, reflectionCacheSize) - private val javaMemberIsRequired = LRUMap(reflectionCacheSize, reflectionCacheSize) + private val javaMemberIsRequired = LRUMap(reflectionCacheSize, reflectionCacheSize) // Initial size is 0 because the value class is not always used private val valueClassReturnTypeCache: LRUMap>> = @@ -102,8 +83,8 @@ internal class ReflectionCache(reflectionCacheSize: Int) : Serializable { ) } // we cannot reflect this method so do the default Java-ish behavior - fun javaMemberIsRequired(key: AnnotatedMember, calc: (AnnotatedMember) -> Boolean?): Boolean? = javaMemberIsRequired.get(key)?.value - ?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, BooleanTriState.fromBoolean(it))?.value ?: it } + fun javaMemberIsRequired(key: AnnotatedMember, calc: (AnnotatedMember) -> Boolean?): Boolean? = javaMemberIsRequired.get(key)?.asBoolean() + ?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, OptBoolean.fromBoolean(it))?.asBoolean() ?: it } private fun AnnotatedMethod.getValueClassReturnType(): KClass<*>? { val getter = this.member.apply {