Skip to content

Add support for Kotlin inline/value classes in BeanUtils #28638

Closed
@MrBuddyCasino

Description

@MrBuddyCasino

Kotlin value classes currently cannot be used in configuration bindings in Spring Boot 2.6.6.

This is a repro case:

package com.example

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.context.properties.ConstructorBinding
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean

fun main(args: Array<String>) {
    System.setProperty("SPRING_APPLICATION_JSON", "{ \"predicate\": \"C\" }")
    runApplication<SpringTest>(*args)
}

@SpringBootApplication
@ConfigurationPropertiesScan(basePackages = ["com.example"])
class SpringTest {

    @Bean
    fun someBean(config: PredicateConfiguration): String {
        println("predicate: ${config.predicate.value}")
        return ""
    }

}

@JvmInline
value class Predicate(val value: Char)

@ConfigurationProperties
@ConstructorBinding
data class PredicateConfiguration(val predicate: Predicate)

It fails with the following error message:

Failed to bind properties under '' to com.example.PredicateConfiguration:

    Reason: java.lang.IllegalArgumentException: object is not an instance of declaring class

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: kotlinAn issue related to Kotlin supporttype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions