Unable to discover private factory functions in Kotlin 1.5.x/jackson-module-kotlin 2.13.x
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.)
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.
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.