If I have this as my configuration properties: ``...
# spring
d
If I have this as my configuration properties:
Copy code
kotlin
@ConstructorBinding
@ConfigurationProperties("company")
class UsersProperties(val users: Map<String, User>) {
    data class User(
        val password: String,
        val companyName: String,
        val accounts: List<String>
    )
}
and this in my application.yaml
Copy code
yaml
company:
  users:
    <mailto:admin@email.com|admin@email.com>:
      password: admin
      companyName: Company 1
      accounts: [ "ACC1", "ACC2" ]
    <mailto:user@user.com|user@user.com>:
      password: user
      companyName: Company 2
      accounts: [ "ACC3", "ACC4" ]
spring complains that
users
property can't be null Any idea? Thanks in advance
j
This has to do with the dot in the emails. Spring transforms this Yaml into properties-based documents, and the properties are thus named
company.users.admin@email.com.password
for example, where the dot in the email address now becomes a property separator. You should probably use a list of users, with an additional
email
property, and simply have a
toMap()
method in the properties that returns the list of users as a map.
d
Thanks, that'll do the trick!