Dendin
Dendin

Reputation: 173

When prefix is missing for config properties, make the map to empty and not null

Currently, if my application.yml does not include the mapping of a property, my config class does not initializes the map and leaves it as null instead of empty. How can i make it be empty if no mapping is found?

@Configuration
@ConfigurationProperties(prefix = "someMapping")
@EnableConfigurationProperties
@Getter
@Setter
public class HttpLoggingLevelProperties {
    private Map<String, String> loggingLevelMap;
}

Upvotes: 1

Views: 1145

Answers (1)

Steve Benett
Steve Benett

Reputation: 12933

Just initialize the map yourself. In the default constructor or directly on the field.

private Map<String, String> loggingLevelMap = new HashMap<>();

Upvotes: 1

Related Questions