Skip to content

New Kotlin annotation default results in Duplicate injectable value error #1012

@josephlbarnett

Description

@josephlbarnett

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

The new kotlin annotation defaulting rule described here: https://youtrack.jetbrains.com/issue/KT-73255 is introduced in kotlin 2.2.0 as opt-in (-Xannotation-default-target=param-property). Enabling it causes this test to fail with:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Problem with definition of [AnnotedClass com.trib3.json.InjectedValueBean]: Duplicate injectable value with id 'Key[type=com.trib3.json.SimpleBean, annotation=[none]]' (of type `com.google.inject.Key`)
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1]

To Reproduce

https://github.com/josephlbarnett/leakycauldron/blob/main/json/src/test/kotlin/com/trib3/json/ObjectMapperTest.kt#L171-L179 tries to read an InjectedValueBean from json with this bean definition:

private data class SimpleBean(
    val foo: String,
    val bar: Int,
    val maybe: String?,
    val date: LocalDate?,
    val ignoreMe: String? = null,
)

private data class InjectedValueBean(
    val foo: String,
    val bar: Int,
    @JacksonInject
    val injectedBeanDefault: SimpleBean,
    @JacksonInject(useInput = OptBoolean.TRUE)
    val injectedBeanTrue: SimpleBean,
    @JacksonInject(useInput = OptBoolean.FALSE)
    val injectedBeanFalse: SimpleBean,
)

Expected behavior

changing the @JacksonInjects to @param:JacksonInjects in the InjectedValueBean definition fixes the issue, but would be nice to not have to

Versions

Kotlin: 2.2.0
Jackson-module-kotlin: 2.19.0
Jackson-databind: 2.19.0

Additional context

initially filed as FasterXML/jackson-databind#5206 but asked to move here (there may be a way to generate a java class that reproduces this in contrast to checkbox 4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions