You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an immutable @ConfigurationProperties class with nested properties:
package com.example.demo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.boot.context.properties.bind.DefaultValue;
@ConfigurationProperties
@ConstructorBinding
public class NestedConfigurationProperties {
private final NestedProperties nested;
private final String property;
public NestedConfigurationProperties(
NestedProperties nested,
String property) {
this.nested = nested;
this.property = property;
}
public NestedProperties getNested() {
return nested;
}
public String getProperty() {
return property;
}
public static class NestedProperties {
private final String nestedProperty;
public NestedProperties(@DefaultValue("default_value") String nestedProperty) {
this.nestedProperty = nestedProperty;
}
public String getNestedProperty() {
return nestedProperty;
}
}
}
When I bind the class without specifying a value for the nested property the nested properties holder object is null. A test illustrating my expectations:
Unless I set a value for a nested property (properties.put("nested.nested_property", "some value")) the NestedConfigurationProperties#nested field is null.
Expected result
The nested properties object is never null when binding the top-level properties.
The text was updated successfully, but these errors were encountered:
This is a duplicate of #18917. The fix for that will be available in Spring Boot 2.2.7. An empty @DefaultValue on the constructor parameter indicates the property should never be null even when nothing was bound to it. You can give it a try with the 2.2.7 snapshots.
Version information
Spring-boot: 2.2.6.RELEASE
Reproduction
I have an immutable
@ConfigurationProperties
class with nested properties:When I bind the class without specifying a value for the nested property the nested properties holder object is null. A test illustrating my expectations:
Unless I set a value for a nested property (
properties.put("nested.nested_property", "some value")
) theNestedConfigurationProperties#nested
field is null.Expected result
The nested properties object is never null when binding the top-level properties.
The text was updated successfully, but these errors were encountered: