Skip to content

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

@k163377

Description

@k163377

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. Since jackson-module-kotlin still uses Kotlin 1.5 in 2.15, this problem may continue to occur.

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions