Skip to content

List with object in configuration properties are not mapped into object from ENV variables #46638

@radeklos

Description

@radeklos

I have list of objects in my properties and I want populate them by env variables. Spring boot version = 3.5.3.

Example of my properties structure:

my:
  tests:
    - a: foo
      b: bar
    - a: hello
      b: world

My kotlin code:

data class Test(val a: String, val b: String)

@ConfigurationProperties(prefix = "my")
data class MyProperties(val tests: List<Test>)

and I want fill them with environment variables:

MY_TESTS_0_A=foo
MY_TESTS_0_B=bar
MY_TESTS_1_A=hello
MY_TESTS_1_B=world

But the tests is always empty.

I tried multiple combination with list of Strings or object with single field. Both works.

@ConfigurationProperties(prefix = "my")
data class MyProperties(val tests: List<String>)
MY_TESTS_0=foo
MY_TESTS_1=bar
data class Test(val a: String, val b: String)

@ConfigurationProperties(prefix = "my")
data class MyProperties(val tests: List<String>)
MY_TESTS_0=foo
MY_TESTS_1=bar

The mapping somehow works, but not for objects with multiple fields.


Workaround is to use env SPRING_APPLICATION_JSON and pass values as JSON.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions