Class JaxrsValidationException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.kiwiproject.jaxrs.exception.JaxrsException
-
- org.kiwiproject.jaxrs.exception.JaxrsValidationException
-
- All Implemented Interfaces:
Serializable
public class JaxrsValidationException extends JaxrsException
Exception representing a 422 status code that extendsJaxrsExceptionto use Kiwi'sErrorMessage.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intCODEThe status code for all instances of this exception.
-
Constructor Summary
Constructors Constructor Description JaxrsValidationException(String itemId, List<Map<String,String>> errorMessageMaps)New instance with given item ID and error messages.JaxrsValidationException(String itemId, Set<? extends javax.validation.ConstraintViolation<?>> violations)New instance with given item ID and constraint violations.JaxrsValidationException(String itemId, Set<? extends javax.validation.ConstraintViolation<?>> violations, Map<String,String> propertyPathMappings)New instance with given item ID, constraint violations, and a map containing entries whose keys are the property path of theConstraintViolationand values are the field/property name that should be used in place of the property path.JaxrsValidationException(List<ErrorMessage> errorMessages)New instance with givenErrorMessageobjects.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JaxrsValidationExceptionofErrorMessages(List<ErrorMessage> errorMessages)Factory method to create validation exception from a non-null list ofErrorMessage.-
Methods inherited from class org.kiwiproject.jaxrs.exception.JaxrsException
buildJaxrsException, getErrorCode, getErrors, getOtherData, getRollUpStatus, getStatusCode, setErrors, setOtherData
-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Field Detail
-
CODE
public static final int CODE
The status code for all instances of this exception.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JaxrsValidationException
public JaxrsValidationException(String itemId, List<Map<String,String>> errorMessageMaps)
New instance with given item ID and error messages.Each map contained in
errorMessageMapsmust have entries with at least two keys:ErrorMessage.KEY_FIELD_NAMEandErrorMessage.KEY_MESSAGE. In other words, the maps should contain an entry whose key isErrorMessage.KEY_FIELD_NAMEand another entry whose key isErrorMessage.KEY_MESSAGE. Any other entries are ignored. The value of these two entries become the field name and message in the resultingErrorMessageobjects.- Parameters:
itemId- the unique ID of the item that caused this errorerrorMessageMaps- a list containing maps containing
-
JaxrsValidationException
public JaxrsValidationException(String itemId, Set<? extends javax.validation.ConstraintViolation<?>> violations)
New instance with given item ID and constraint violations.- Parameters:
itemId- the unique ID of the item that caused this errorviolations- the constraint violations to transform intoErrorMessageobjects
-
JaxrsValidationException
public JaxrsValidationException(String itemId, Set<? extends javax.validation.ConstraintViolation<?>> violations, Map<String,String> propertyPathMappings)
New instance with given item ID, constraint violations, and a map containing entries whose keys are the property path of theConstraintViolationand values are the field/property name that should be used in place of the property path.For example,
propertyPathMappingsmight contain an entry with key "firstName" and value "First Name". In the resulting instance, the correspondingErrorMessageobject contained in the list returned byJaxrsException.getErrors()will have "First Name" as the field name.- Parameters:
itemId- the unique ID of the item that caused this errorviolations- the constraint violations to transform intoErrorMessageobjectspropertyPathMappings- mappings from property path of aConstraintViolationto the field name to use in theErrorMessageobjects
-
JaxrsValidationException
public JaxrsValidationException(List<ErrorMessage> errorMessages)
New instance with givenErrorMessageobjects.It is assumed but not checked that the
ErrorMessageobjects are due to 422 errors. Therefore it is possible to instantiate an instance with errors that have some other status code.- Parameters:
errorMessages- non-null list of error messages
-
-
Method Detail
-
ofErrorMessages
public static JaxrsValidationException ofErrorMessages(List<ErrorMessage> errorMessages)
Factory method to create validation exception from a non-null list ofErrorMessage.- Parameters:
errorMessages- non-null list of error messages- Returns:
- a new
JaxrsValidationExceptioninstance - See Also:
JaxrsValidationException(List)
-
-