-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43886 from quaff
* gh-43886: Polish "Add spring.validation.method.adapt-constraint-violations property" Add spring.validation.method.adapt-constraint-violations property Closes gh-43886
- Loading branch information
Showing
5 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/main/java/org/springframework/boot/autoconfigure/validation/ValidationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2012-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.autoconfigure.validation; | ||
|
||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Role; | ||
|
||
/** | ||
* {@link ConfigurationProperties @ConfigurationProperties} for validation. | ||
* | ||
* @author Yanming Zhou | ||
* @author Andy Wilkinson | ||
* @since 3.5.0 | ||
*/ | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) | ||
@ConfigurationProperties(prefix = "spring.validation") | ||
public class ValidationProperties { | ||
|
||
private Method method = new Method(); | ||
|
||
public Method getMethod() { | ||
return this.method; | ||
} | ||
|
||
public void setMethod(Method method) { | ||
this.method = method; | ||
} | ||
|
||
/** | ||
* Method validation properties. | ||
*/ | ||
public static class Method { | ||
|
||
/** | ||
* Whether to adapt ConstraintViolations to MethodValidationResult. | ||
*/ | ||
private boolean adaptConstraintViolations; | ||
|
||
public boolean isAdaptConstraintViolations() { | ||
return this.adaptConstraintViolations; | ||
} | ||
|
||
public void setAdaptConstraintViolations(boolean adaptConstraintViolations) { | ||
this.adaptConstraintViolations = adaptConstraintViolations; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...est/java/org/springframework/boot/autoconfigure/validation/ValidationPropertiesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.autoconfigure.validation; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link ValidationProperties}. | ||
* | ||
* @author Andy Wilkinson | ||
*/ | ||
class ValidationPropertiesTests { | ||
|
||
@Test | ||
void adaptConstraintViolationsPropertyDefaultMatchesPostProcessorDefault() { | ||
assertThat(new MethodValidationPostProcessor()).extracting("adaptConstraintViolations") | ||
.isEqualTo(new ValidationProperties().getMethod().isAdaptConstraintViolations()); | ||
} | ||
|
||
} |