Class ViolationCollector
java.lang.Object
io.dropwizard.validation.selfvalidating.ViolationCollector
This class is a simple wrapper around the ConstraintValidatorContext of hibernate validation.
It collects all the violations of the SelfValidation methods of an object.
-
Constructor Summary
ConstructorsConstructorDescriptionViolationCollector(jakarta.validation.ConstraintValidatorContext constraintValidatorContext) Constructs a newViolationCollectorwith the givenConstraintValidatorContext. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddViolation(String message) Adds a new violation to this collector.voidaddViolation(String propertyName, Integer index, String message) Adds a new violation to this collector.voidaddViolation(String propertyName, Integer index, String message, Map<String, Object> messageParameters) Adds a new violation to this collector.voidaddViolation(String propertyName, String message) Adds a new violation to this collector.voidaddViolation(String propertyName, String key, String message) Adds a new violation to this collector.voidAdds a new violation to this collector.voidAdds a new violation to this collector.voidaddViolation(String message, Map<String, Object> messageParameters) Adds a new violation to this collector.jakarta.validation.ConstraintValidatorContextThis method returns the wrapped context for raw access to the validation framework.booleanReturns, if a violation has previously occurred.voidsetViolationOccurred(boolean violationOccurred) Manually sets if a violation occurred.
-
Constructor Details
-
ViolationCollector
public ViolationCollector(jakarta.validation.ConstraintValidatorContext constraintValidatorContext) Constructs a newViolationCollectorwith the givenConstraintValidatorContext.- Parameters:
constraintValidatorContext- the wrappedConstraintValidatorContext
-
-
Method Details
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue.
Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
message- the message of the violation- See Also:
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
message- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue.
Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
propertyName- the name of the propertymessage- the message of the violation- Since:
- 2.0.2
- See Also:
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the propertymessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue. Prefer the method with explicit message parameters if you want to interpolate the message.- Parameters:
propertyName- the name of the property with the violationindex- the index of the element with the violationmessage- the message of the violation (any EL expression will be escaped and not parsed)- Since:
- 2.0.2
- See Also:
-
addViolation
public void addViolation(String propertyName, Integer index, String message, Map<String, Object> messageParameters) Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationindex- the index of the element with the violationmessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationkey- the key of the element with the violationmessage- the message of the violation- Since:
- 2.0.2
-
addViolation
public void addViolation(String propertyName, String key, String message, Map<String, Object> messageParameters) Adds a new violation to this collector. This also setsviolationOccurredtotrue.- Parameters:
propertyName- the name of the property with the violationkey- the key of the element with the violationmessage- the message of the violationmessageParameters- a map of message parameters which can be interpolated in the violation message- Since:
- 2.0.3
-
getContext
public jakarta.validation.ConstraintValidatorContext getContext()This method returns the wrapped context for raw access to the validation framework. If you use the context to add violations make sure to callsetViolationOccurred(true).- Returns:
- the wrapped Hibernate ConstraintValidatorContext
-
hasViolationOccurred
public boolean hasViolationOccurred()Returns, if a violation has previously occurred.- Returns:
- if any violation was collected
-
setViolationOccurred
public void setViolationOccurred(boolean violationOccurred) Manually sets if a violation occurred. This is automatically set ifaddViolationis called.- Parameters:
violationOccurred- if any violation was collected
-