0

I've seen examples of how to do this in Java but I'm lacking an example in Kotlin. I want to read a property into a boolean using the @Value annotation from Spring

In my constructor I'm doing:

@Value("\${kafka.userComplexTopics:false}")
val useComplexTopicsString: String,

to pull out my String value and then in my class I have:

private val useComplexTopics = useComplexTopicsString.toBoolean()

I've been screwing around with SePL and can't make it work in one line.

Jeef
  • 26,861
  • 21
  • 78
  • 156

1 Answers1

3

Spring should do this conversion for you. Unless you need the Stringified version, try setting your type to a Boolean.

@Component
class SomeClass(
    @Value("\${kafka.useComplexTopics:false}") val useComplexTopics: Boolean
) {
    init {
        println("UseComplexTopics: $useComplexTopics")
    }
}
Todd
  • 30,472
  • 11
  • 81
  • 89