Skip to content

Commit

Permalink
Merge pull request #8 from tedliang/fixViolationPathForContainerEleme…
Browse files Browse the repository at this point in the history
…ntNode

Avoid using Node.toString to resolve ViolationPath
  • Loading branch information
tedliang authored Nov 27, 2021
2 parents 30c5ee6 + 05e6dff commit 88a4aa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ java {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjvm-default=enable")
freeCompilerArgs = listOf("-Xjvm-default=enable", "-java-parameters")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


class ValidatingValueInstantiator extends AbstractDelegatingValueInstantiator {
Expand Down Expand Up @@ -227,22 +225,21 @@ private ConstraintViolation<?> mapParameterViolation(

if (features.isEnabled(BeanValidationFeature.MAP_CREATOR_VIOLATIONS_TO_PROPERTY_VIOLATIONS)) {

String propertyName;
PathBuilder pathBuilder = PathBuilder.create();

if (features.isEnabled(BeanValidationFeature.REPORT_BEAN_PROPERTY_PATHS_IN_VIOLATIONS)) {
propertyName = parameterNode.getName();
pathBuilder.appendBeanNode().appendProperty(parameterNode.getName());

} else {
propertyName = constructorArguments[parameterIndex].getName();
}
String propertyName = constructorArguments[parameterIndex].getName();

Matcher containerIndex = Pattern.compile("\\[.*\\]").matcher(parameterNode.toString());
if (containerIndex.find()) {
propertyName += containerIndex.group();
if (propertyName.equals(parameterNode.getName())) {
pathBuilder.appendNode(parameterNode);
} else {
pathBuilder.appendBeanNode().appendProperty(propertyName);
}
}

Path newPath = PathBuilder.create()
.appendBeanNode()
.appendProperty(propertyName)
Path newPath = pathBuilder
.appendPath(PathUtils.dropUntil(violation.getPropertyPath(), ElementKind.PARAMETER))
.build();

Expand Down

0 comments on commit 88a4aa1

Please sign in to comment.