jackson-module-kotlin icon indicating copy to clipboard operation
jackson-module-kotlin copied to clipboard

Unable to discover private factory functions in Kotlin 1.5.x/jackson-module-kotlin 2.13.x

Open k163377 opened this issue 3 years ago • 1 comments

Describe the bug In Kotlin 1.5.x, access to private JvmStatic functions via Java reflection is broken. https://youtrack.jetbrains.com/issue/KT-46181

This causes problems with code like the following, where the JsonCreator is ignored and the primary constructor is called, or when the constructor call is disabled, there is no function to call and instantiation fails.

class Foo private constructor(val foo: Int, val bar: Int) {
    companion object {
        @JvmStatic
        @JsonCreator
        private fun creator(foo: Int, bar: Int) = Foo(foo, bar)
    }
}

Note that if you run it with Intellij, the Kotlin version of the IDE side will take precedence and this issue may not occur. #533, It was able to reproduce the problem by running the test with mvn verify.

To Reproduce #533

Additional context If this problem occurs and library versions cannot be changed, there seems to be no workaround other than setting the factory function to public. The jackson-module-kotlin 2.14 solves this problem because the Kotlin version is 1.6.x.

We may also add tests in jackson-module-kotlin 2.13 that will run on non-Kotlin 1.5.x (in environments like Intellij). (However, we consider the implementation of this test to be low priority. PRs are welcome to add this test.)

k163377 avatar Jan 08 '22 00:01 k163377

Not sure but for 1.6.* kotlin and 2.13.1 it also occurs, I faced it on android in release mode so... in debug everything worked, after falling back to 1.5.30 kotlin and 2.12.5 it works again.

Azbesciak avatar Jan 13 '22 16:01 Azbesciak

Since the minimum supported Kotlin version is 1.6 for Jackson 2.16 and later, this issue has been closed. Please submit a new issue for Kotlin 1.6 or later as it may be due to other causes.

k163377 avatar Jul 15 '23 14:07 k163377