From 1f8c1a5bf990149502b8098681b321741a73ada6 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 2 May 2021 17:03:48 +0900 Subject: [PATCH 1/2] add test --- .../module/kotlin/test/ParameterNameTests.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt index 50205a649..64169d4f0 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt @@ -197,6 +197,23 @@ class TestJacksonWithKotlin { } } + private class StateObjectWithFactoryOnNamedCompanion private constructor (override val name: String, override val age: Int, override val primaryAddress: String, override val wrongName: Boolean, override val createdDt: Date) : TestFields { + var factoryUsed: Boolean = false + companion object Named { + @JvmStatic @JsonCreator fun create(@JsonProperty("name") nameThing: String, @JsonProperty("age") age: Int, @JsonProperty("primaryAddress") primaryAddress: String, @JsonProperty("renamed") wrongName: Boolean, @JsonProperty("createdDt") createdDt: Date): StateObjectWithFactoryOnNamedCompanion { + val obj = StateObjectWithFactoryOnNamedCompanion(nameThing, age, primaryAddress, wrongName, createdDt) + obj.factoryUsed = true + return obj + } + } + } + + @Test fun findingFactoryMethod3() { + val stateObj = normalCasedMapper.readValue(normalCasedJson, StateObjectWithFactoryOnNamedCompanion::class.java) + stateObj.validate() + assertThat(stateObj.factoryUsed, equalTo(true)) + } + // GH #14 failing due to this enum type data class Gh14FailureWithEnum(var something: String = "hi", var someEnum: LaunchType = LaunchType.ACTIVITY) From 73ba4798238a79c7217ca9ab54641d8b78d04bde Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 2 May 2021 17:04:36 +0900 Subject: [PATCH 2/2] fix cond --- .../fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt index ee55e9494..aed1ee847 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinValueInstantiator.kt @@ -71,7 +71,7 @@ internal class KotlinValueInstantiator( possibleCompanion.objectInstance } catch (ex: IllegalAccessException) { // fallback for when an odd access exception happens through Kotlin reflection - val companionField = possibleCompanion.java.enclosingClass.fields.firstOrNull { it.name == "Companion" } + val companionField = possibleCompanion.java.enclosingClass.fields.firstOrNull { it.type.kotlin.isCompanion } ?: throw ex val accessible = companionField.isAccessible if ((!accessible && ctxt.config.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)) ||