Skip to content

Empty @DefaultValue cannot be used on collections, maps, arrays or optional values #32559

@wind57

Description

@wind57

I have this simple configuration:

@ConfigurationProperties("dummy")
public record TestRecord(@DefaultValue Set<String> values, @DefaultValue("default") String one) {
}

This fails with : Parameter of type java.util.Set<java.lang.String> must have a non-empty default value.

What I would like to get as a default value is an empty Set. Of course as a workaround, I can:

public Set<String> values() {
    return values == null ? Set.of() : values;
}

but considering there are any of these default collections/maps, I do not want to add an accessor for each of the properties. Is there are a way to make @DefaultValue "return" an empty Set? thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions