mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 20:19:06 +00:00
Merge pull request #50798 from xfocus3
Closes gh-50798 * gh-50798: Handle unresolved validation target types
This commit is contained in:
+1
-3
@@ -34,7 +34,6 @@ import org.springframework.boot.context.properties.source.ConfigurationProperty;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertyName.Form;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.AbstractBindingResult;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
@@ -115,8 +114,7 @@ public class ValidationBindHandler extends AbstractBindHandler {
|
||||
if (this.exception == null) {
|
||||
Object validationTarget = getValidationTarget(target, context, result);
|
||||
Class<?> validationType = target.getBoxedType().resolve();
|
||||
if (validationTarget != null) {
|
||||
Assert.state(validationType != null, "'validationType' must not be null");
|
||||
if (validationTarget != null && validationType != null) {
|
||||
validateAndPush(name, validationTarget, validationType);
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -238,6 +238,15 @@ class ValidationBindHandlerTests {
|
||||
this.binder.bind(ConfigurationPropertyName.of("test"), Bindable.of(ExampleWithMap.class), this.handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindShouldValidateMapWithWildcardValue() {
|
||||
this.sources.add(new MockConfigurationPropertySource("test.params.toto", "titi"));
|
||||
ExampleWithWildcardMap result = this.binder
|
||||
.bind(ConfigurationPropertyName.of("test"), Bindable.of(ExampleWithWildcardMap.class), this.handler)
|
||||
.get();
|
||||
assertThat(result.getParams().get("toto")).isEqualTo("titi");
|
||||
}
|
||||
|
||||
private Validator getMapValidator() {
|
||||
return new Validator() {
|
||||
|
||||
@@ -425,6 +434,21 @@ class ValidationBindHandlerTests {
|
||||
|
||||
}
|
||||
|
||||
@Validated
|
||||
static class ExampleWithWildcardMap {
|
||||
|
||||
private Map<String, ?> params = new LinkedHashMap<>();
|
||||
|
||||
Map<String, ?> getParams() {
|
||||
return this.params;
|
||||
}
|
||||
|
||||
void setParams(Map<String, ?> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class ExampleMapValue {
|
||||
|
||||
private @Nullable String number;
|
||||
|
||||
Reference in New Issue
Block a user