Package org.everit.json.schema
Class ValidationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.everit.json.schema.ValidationException
- All Implemented Interfaces:
Serializable
Thrown by
Schema subclasses on validation failure.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionValidationException(Class<?> expectedType, Object actualValue) Deprecated.ValidationException(String message) Deprecated.ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue) Constructor, creates an instance withkeyword="type".ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword) Deprecated.ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword, String schemaLocation) Constructor for type-mismatch failures.ValidationException(Schema violatedSchema, String message) Deprecated.use one of the constructors which explicitly specify the violated keyword insteadValidationException(Schema violatedSchema, String message, String keyword) Deprecated.ValidationException(Schema violatedSchema, String message, String keyword, String schemaLocation) Constructor.ValidationException(Schema violatedSchema, String message, List<ValidationException> causingExceptions) Deprecated.use one of the constructors which explicitly specify the keyword instead -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns all messages collected from all violations, including nested causing exceptions.Returns a programmer-readable error description.Returns a programmer-readable error description prepended bythe pointer to the violating fragmentof the JSON document.A JSON pointer denoting the part of the document which violates the schema.intinthashCode()Creates a newViolationExceptioninstance based on this one, but with changedJSON pointer.Creates a newViolationExceptioninstance based on this one, but with changedJSON pointerand {linkviolated schema.static voidthrowFor(Schema rootFailingSchema, List<ValidationException> failures) Sort of static factory method.org.json.JSONObjecttoJSON()Creates a JSON representation of the failure.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ValidationException
Deprecated.Deprecated, useValidationException(Schema, Class<?>, Object)instead.- Parameters:
expectedType- the expected typeactualValue- the violating value
-
ValidationException
Constructor, creates an instance withkeyword="type".- Parameters:
violatedSchema- the schema instance which detected the schema violationexpectedType- the expected typeactualValue- the violating value
-
ValidationException
@Deprecated public ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword) Deprecated.Constructor for type-mismatch failures. It is usually more convenient to useValidationException(Schema, Class, Object)instead.- Parameters:
violatedSchema- the schema instance which detected the schema violationexpectedType- the expected typeactualValue- the violating valuekeyword- the violating keyword
-
ValidationException
public ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword, String schemaLocation) Constructor for type-mismatch failures. It is usually more convenient to useValidationException(Schema, Class, Object)instead.- Parameters:
violatedSchema- the schema instance which detected the schema violationexpectedType- the expected typeactualValue- the violating valuekeyword- the violating keywordschemaLocation- a path denoting the location of the violated keyword in the schema JSON
-
ValidationException
Deprecated.use one of the constructors which explicitly specify the violated keyword insteadConstructor.- Parameters:
violatedSchema- the schema instance which detected the schema violationmessage- the readable exception message
-
ValidationException
Deprecated.Constructor.- Parameters:
violatedSchema- the schama instance which detected the schema violationmessage- the readable exception messagekeyword- the violated keyword
-
ValidationException
public ValidationException(Schema violatedSchema, String message, String keyword, String schemaLocation) Constructor.- Parameters:
violatedSchema- the schama instance which detected the schema violationmessage- the readable exception messagekeyword- the violated keywordschemaLocation- the path to the violated schema fragment (from the schema root)
-
ValidationException
Deprecated.Deprecated, useValidationException(Schema, String)instead.- Parameters:
message- readable exception message
-
ValidationException
@Deprecated public ValidationException(Schema violatedSchema, String message, List<ValidationException> causingExceptions) Deprecated.use one of the constructors which explicitly specify the keyword insteadConstructor.- Parameters:
violatedSchema- the schema instance which detected the schema violationmessage- the readable exception messagecausingExceptions- a (possibly empty) list of validation failures. It is used if multiple schema violations are found by violatedSchema
-
-
Method Details
-
throwFor
Sort of static factory method. It is used byObjectSchemaandArraySchemato createValidationExceptions, handling the case of multiple violations occuring during validation.- If
failuresis empty, then it doesn't do anything - If
failurescontains 1 exception instance, then that will be thrown - Otherwise a new exception instance will be created, its
violated schemawill berootFailingSchema, and itscausing exceptionswill be thefailureslist
- Parameters:
rootFailingSchema- the schema which detected thefailuresfailures- list containing validation failures to be thrown by this method
- If
-
getCausingExceptions
-
getAllMessages
Returns all messages collected from all violations, including nested causing exceptions.- Returns:
- all messages
-
getMessage
Returns a programmer-readable error description prepended bythe pointer to the violating fragmentof the JSON document.- Overrides:
getMessagein classThrowable- Returns:
- the error description
-
getErrorMessage
Returns a programmer-readable error description. UnlikegetMessage()this doesn't contain the JSON pointer denoting the violating document fragment.- Returns:
- the error description
-
getPointerToViolation
A JSON pointer denoting the part of the document which violates the schema. It always points from the root of the document to the violating data fragment, therefore it always starts with#.- Returns:
- the JSON pointer
-
getViolatedSchema
-
prepend
Creates a newViolationExceptioninstance based on this one, but with changedJSON pointer.- Parameters:
fragment- the fragment of the JSON pointer to be prepended to existing pointers- Returns:
- the new instance
-
prepend
Creates a newViolationExceptioninstance based on this one, but with changedJSON pointerand {linkviolated schema.- Parameters:
fragment- the fragment of the JSON pointer to be prepended to existing pointersviolatedSchema- the violated schema, which may not be the same asgetViolatedSchema()- Returns:
- the new
ViolationExceptioninstance
-
getViolationCount
public int getViolationCount() -
getKeyword
-
toJSON
public org.json.JSONObject toJSON()Creates a JSON representation of the failure.The returned
JSONObjectcontains the following keys:"message": a programmer-friendly exception message. This value is a non-nullable string."keyword": a JSON Schema keyword which was used in the schema and violated by the input JSON. This value is a nullable string."pointerToViolation": a JSON Pointer denoting the path from the root of the document to the invalid fragment of it. This value is a non-nullable string. SeegetPointerToViolation()"causingExceptions": is a (possibly empty) array of violations which caused this exception. SeegetCausingExceptions()"schemaLocation": a string denoting the path to the violated schema keyword in the schema JSON (since version 1.6.0)
- Returns:
- a JSON description of the validation error
-
getSchemaLocation
- Returns:
- a path denoting the location of the violated keyword in the schema
- Since:
- 1.6.0
-
equals
-
hashCode
public int hashCode()
-