Skip to content

Commit fbf0929

Browse files
committed
Merge pull request #52877 from anqorithm
Closes gh-52877 * pr/52877: Keep bind restrictions when Bindable.withAnnotations is called
2 parents ebd9a50 + 45866ed commit fbf0929

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

  • core/spring-boot/src

‎core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Bindable.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private boolean nullSafeEquals(@Nullable Object o1, @Nullable Object o2) {
170170
*/
171171
public Bindable<T> withAnnotations(Annotation @Nullable ... annotations) {
172172
return new Bindable<>(this.type, this.boxedType, this.value,
173-
(annotations != null) ? annotations : NO_ANNOTATIONS, NO_BIND_RESTRICTIONS, this.bindMethod);
173+
(annotations != null) ? annotations : NO_ANNOTATIONS, this.bindRestrictions, this.bindMethod);
174174
}
175175

176176
/**

‎core/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindableTests.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ void withBindRestrictionAddsBindRestriction() {
189189
assertThat(restricted.hasBindRestriction(BindRestriction.NO_DIRECT_PROPERTY)).isTrue();
190190
}
191191

192+
@Test
193+
void withAnnotationsDoesNotForgetBindRestrictions() {
194+
Annotation annotation = AnnotationUtils.synthesizeAnnotation(TestAnnotation.class);
195+
Bindable<String> bindable = Bindable.of(String.class)
196+
.withBindRestrictions(BindRestriction.NO_DIRECT_PROPERTY)
197+
.withAnnotations(annotation);
198+
assertThat(bindable.hasBindRestriction(BindRestriction.NO_DIRECT_PROPERTY)).isTrue();
199+
}
200+
192201
@Test
193202
void whenTypeCouldUseJavaBeanOrValueObjectJavaBeanBindingCanBeSpecified() {
194203
BindMethod bindMethod = Bindable.of(JavaBeanOrValueObject.class)

0 commit comments

Comments
 (0)