generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save attribute
validatedPath
in MessageInterpolatorContext
Fixed #265
- Loading branch information
Showing
7 changed files
with
113 additions
and
39 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
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
61 changes: 61 additions & 0 deletions
61
...in/java/io/micronaut/validation/validator/messages/DefaultMessageInterpolatorContext.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,61 @@ | ||
/* | ||
* Copyright 2017-2024 original 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 io.micronaut.validation.validator.messages; | ||
|
||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.validation.validator.DefaultConstraintValidatorContext; | ||
import jakarta.validation.MessageInterpolator; | ||
import jakarta.validation.ValidationException; | ||
import jakarta.validation.metadata.ConstraintDescriptor; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
public class DefaultMessageInterpolatorContext implements MessageInterpolator.Context { | ||
|
||
private final DefaultConstraintValidatorContext<?> validatorContext; | ||
private final ConstraintDescriptor<Annotation> constraintDescriptor; | ||
@Nullable | ||
private final Object validatedValue; | ||
|
||
public DefaultMessageInterpolatorContext( | ||
DefaultConstraintValidatorContext<?> validatorContext, | ||
ConstraintDescriptor<Annotation> constraintDescriptor, | ||
@Nullable Object validatedValue | ||
) { | ||
this.validatorContext = validatorContext; | ||
this.constraintDescriptor = constraintDescriptor; | ||
this.validatedValue = validatedValue; | ||
} | ||
|
||
public DefaultConstraintValidatorContext<?> getValidatorContext() { | ||
return validatorContext; | ||
} | ||
|
||
@Override | ||
public ConstraintDescriptor<?> getConstraintDescriptor() { | ||
return constraintDescriptor; | ||
} | ||
|
||
@Override | ||
public Object getValidatedValue() { | ||
return validatedValue; | ||
} | ||
|
||
@Override | ||
public <T> T unwrap(Class<T> type) { | ||
throw new ValidationException("Not supported!"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
validation/src/test/groovy/io/micronaut/validation/validator/MyBook.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,20 @@ | ||
package io.micronaut.validation.validator; | ||
|
||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.validation.Validated; | ||
import jakarta.validation.constraints.Size; | ||
|
||
@Validated | ||
@Introspected | ||
class MyBook { | ||
@Size(max = 2, message = "Check path: {validatedPath} with value: {validatedValue}") | ||
private String title; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
} |
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