Reputation: 173
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
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