Kotlin Spring boot @ConfigurationProperties for list

You are encountering this bug. Simply changing

lateinit var messages: List<Message>

to

var messages: MutableList<Message> = mutableListOf()

makes your code work. Here is a full working example.

edit (March 2019):

As of SB 2.0.0.RC1 and Kotlin 1.2.20, you can use lateinit or a nullable var.

Docs

edit (May 2020):

As of SB 2.2.0 you can use @ConstructorBinding along with @ConfigurationProperties to set val properties on a data class.

Using the original class as an example, you can now write it like so:

@ConstructorBinding
@ConfigurationProperties(prefix = "message")
data class MessageConfig(val messages: List<Message>) {
  data class Message(
    val name: String,
    val type: String,
    val size: BigDecimal
  )
}

Is Fixed in Kotlin 1.3.11 with spring-boot 2.10, sample provided in MessageConfig.kt works now

@PropertySource("classpath:application.yml")
@ConfigurationProperties(value = "message")
class MessageConfig {
  lateinit var messages: List<Message>
}

class Message {
  lateinit var name: String
  lateinit var type: String
  lateinit var size: BigDecimal
}