Browse Source
Update the `Binder` so that empty properties are treated as an indicator
that default value binding should be attempted. This update allow bound
objects to differentiate between a completely missing property vs one
that is present but doesn't have any values.
For example, given the following value object:
@ConfigurationProperties("my")
public record My(Name name, int age) {
public record Name(String first, String last) {
}
}
The following binding scenarios are supported:
1) Full binding
my.name.first=Spring
my.name.last=Boot
my.age=4
Binds to `new My(new Name("Spring", "Boot"), 4)`
(works the same as Spring Boot 4.0)
2) Missing Properties
my.age=4
Binds to `new My(null, 4)`
(works the same as Spring Boot 4.0)
3) Default Properties
my.name=
my.age=4
Binds to `new My(new Name(null, null), 4)`
(previously would throw a converter exception)
Closes gh-48920
pull/49622/merge
10 changed files with 154 additions and 21 deletions
2
documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/nonnull/MyProperties.java → documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/defaultvalues/nonnull/MyProperties.java
2
documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/nonnull/MyProperties.java → documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/defaultvalues/nonnull/MyProperties.java
2
documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/nonnull/MyProperties.kt → documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/defaultvalues/nonnull/MyProperties.kt
2
documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/nonnull/MyProperties.kt → documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/constructorbinding/defaultvalues/nonnull/MyProperties.kt
Loading…
Reference in new issue