Skip to content

Correct section about required setters in "Type-safe Configuration Properties" #43138

@mhalbritter

Description

@mhalbritter

Our documentations says here:

Collections and arrays can be accessed either through an index (typically with YAML) or by using a single comma-separated value (properties). In the latter case, a setter is mandatory. We recommend to always add a setter for such types. If you initialize a collection, make sure it is not immutable (as in the preceding example).

Which isn't true for collections.

Binding this:

@ConfigurationProperties("list")
public class ListConfigProps {
    private final List<String> list = new ArrayList<>();

    public List<String> getList() {
        return this.list;
    }
}

totally works fine, with those properties:

list.list[0]=a
list.list[1]=b

and those:

list.list=a,b

Same works for Set.

For arrays, the paragraph in the documentation holds true.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions