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 newViolationCollector
with the givenConstraintValidatorContext
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addViolation
(String message) Adds a new violation to this collector.void
addViolation
(String propertyName, Integer index, String message) Adds a new violation to this collector.void
addViolation
(String propertyName, Integer index, String message, Map<String, Object> messageParameters) Adds a new violation to this collector.void
addViolation
(String propertyName, String message) Adds a new violation to this collector.void
addViolation
(String propertyName, String key, String message) Adds a new violation to this collector.void
Adds a new violation to this collector.void
Adds a new violation to this collector.void
addViolation
(String message, Map<String, Object> messageParameters) Adds a new violation to this collector.jakarta.validation.ConstraintValidatorContext
This method returns the wrapped context for raw access to the validation framework.boolean
Returns, if a violation has previously occurred.void
setViolationOccurred
(boolean violationOccurred) Manually sets if a violation occurred.
-
Constructor Details
-
ViolationCollector
public ViolationCollector(jakarta.validation.ConstraintValidatorContext constraintValidatorContext) Constructs a newViolationCollector
with the givenConstraintValidatorContext
.- Parameters:
constraintValidatorContext
- the wrappedConstraintValidatorContext
-
-
Method Details
-
addViolation
Adds a new violation to this collector. This also setsviolationOccurred
totrue
.
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 setsviolationOccurred
totrue
.- 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 setsviolationOccurred
totrue
.
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 setsviolationOccurred
totrue
.- 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 setsviolationOccurred
totrue
. 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 setsviolationOccurred
totrue
.- 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 setsviolationOccurred
totrue
.- 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 setsviolationOccurred
totrue
.- 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 ifaddViolation
is called.- Parameters:
violationOccurred
- if any violation was collected
-