Skip to content

Constructor binding fails when configuration class has a generic field with type parameter java.util.Map #19156

@noriyuki106

Description

@noriyuki106

Spring Boot: 2.2.1.RELEASE
Operating System: Mac OS 10.14.6 (Mojave)
Kotlin 1.3.60

In my application, I have a configuration class with generic field, but this does not work with @ConstructorBinding when type parameter is java.util.Map:

@ConfigurationProperties(prefix = "demo.prop")
@ConstructorBinding
data class ConstructorBindingPropWithGeneric(@NestedConfigurationProperty var field: GenericObj<Map<String, String>>) {

    data class GenericObj<T>(
        val subField: T
    )

}

I was using following declaration before @ConstructorBinding, and it was working:

@ConfigurationProperties(prefix = "demo.prop")
class OldStylePropWithGeneric {

    @NestedConfigurationProperty
    var field: GenericObj<Map<String, String>>? = null

    class GenericObj<T> {
        var subField: T? = null
    }

}

I think @ConstructorBinding should work in this case too.

Example project: demo1.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions