Skip to content

Commit 5ee3fda

Browse files
committed
Polish "Allow @DefaultValue to be used on record components"
See gh-29010
1 parent 976ed90 commit 5ee3fda

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/external-config.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,8 @@ Unless your record has multiple constructors, there is no need to use `@Construc
719719

720720
Nested members of a constructor bound class (such as `Security` in the example above) will also be bound through their constructor.
721721

722-
Default values can be specified using `@DefaultValue` and the same conversion service will be applied to coerce the `String` value to the target type of a missing property.
722+
Default values can be specified using `@DefaultValue` on constructor parameters and record components.
723+
The conversion service will be applied to coerce the annotation's `String` value to the target type of a missing property.
723724
By default, if no properties are bound to `Security`, the `MyProperties` instance will contain a `null` value for `security`.
724725
If you wish you return a non-null instance of `Security` even when no properties are bound to it, you can use an empty `@DefaultValue` annotation to do so:
725726

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ void multiConstructorRecordProperties(@TempDir File temp) throws IOException {
447447
}
448448

449449
@Test
450-
@EnabledForJreRange(min = JRE.JAVA_16)
451450
void recordPropertiesWithDefaultValues(@TempDir File temp) throws IOException {
452451
File exampleRecord = new File(temp, "ExampleRecord.java");
453452
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) {

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/DefaultValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ValueObjectBinderTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,8 +33,6 @@
3333
import java.util.Objects;
3434

3535
import org.junit.jupiter.api.Test;
36-
import org.junit.jupiter.api.condition.EnabledForJreRange;
37-
import org.junit.jupiter.api.condition.JRE;
3836
import org.junit.jupiter.api.io.TempDir;
3937

4038
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
@@ -371,7 +369,6 @@ void bindToAnnotationNamedParameter() {
371369
}
372370

373371
@Test
374-
@EnabledForJreRange(min = JRE.JAVA_16)
375372
void bindToRecordWithDefaultValue(@TempDir File tempDir) throws IOException, ClassNotFoundException {
376373
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
377374
source.put("test.record.property1", "value-from-config-1");

0 commit comments

Comments
 (0)