Skip to content

Commit

Permalink
Update release notes wrt #225
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatu Saloranta committed Oct 21, 2019
1 parent 1fa512f commit 3bc79c6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/fasterxml/jackson/**/failing/*.java</exclude>
<exclude>com/fasterxml/jackson/**/failing/*</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ Stéphane B (StephaneBg@github)
* Submitted fix for #176: Version 2.9.7 breaks compatibility with Android minSdk < 24
(2.10.1)

Alain Lehmann (ciderale@github)
* Contributed fix for #225: Don't instantiate new instances of Kotlin singleton objects
(2.10.1)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project: jackson-module-kotlin

#176: Version 2.9.7 breaks compatibility with Android minSdk < 24
(reported jurriaan@github, fix submitted by Stéphane B)
#225: Don't instantiate new instances of Kotlin singleton objects
(reported by Dico200@github; fix by Alain L)
- Make byte code target 1.8 (can't do many things with 1.7 anyway)

2.10.0 (26-Sep-2019)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ 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<*>
) = super.modifyDeserializer(config, beanDesc, deserializer)
.maybeSingletonDeserializer(objectSingletonInstance(beanDesc.beanClass))
}

fun JsonDeserializer<*>.maybeSingletonDeserializer(singleton: Any?) = when (singleton) {
null -> this
else -> this.asSingletonDeserializer(singleton)
): JsonDeserializer<out Any> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class KotlinModule(val reflectionCacheSize: Int = 512, val nullToEmptyCollection

context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap))

// [module-kotlin#225]: keep Kotlin singletons as singletons
context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier)

fun addMixIn(clazz: Class<*>, mixin: Class<*>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.module.kotlin.test
package com.fasterxml.jackson.module.kotlin.test.failing

import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.module.kotlin.test
package com.fasterxml.jackson.module.kotlin.test.failing

import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
Expand Down

0 comments on commit 3bc79c6

Please sign in to comment.