Closed
Description
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