public class ValidationException extends RuntimeException
Schema
subclasses on validation failure.Constructor and Description |
---|
ValidationException(Class<?> expectedType,
Object actualValue)
Deprecated.
|
ValidationException(Schema violatedSchema,
Class<?> expectedType,
Object actualValue)
Constructor, creates an instance with
keyword="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 instead
|
ValidationException(Schema violatedSchema,
String message,
List<ValidationException> causingExceptions)
Deprecated.
use one of the constructors which explicitly specify the keyword instead
|
ValidationException(Schema violatedSchema,
String message,
String keyword)
Deprecated.
|
ValidationException(Schema violatedSchema,
String message,
String keyword,
String schemaLocation)
Constructor.
|
ValidationException(String message)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
List<String> |
getAllMessages()
Returns all messages collected from all violations, including nested causing exceptions.
|
List<ValidationException> |
getCausingExceptions() |
String |
getErrorMessage()
Returns a programmer-readable error description.
|
String |
getKeyword() |
String |
getMessage()
Returns a programmer-readable error description prepended by
the pointer to the violating fragment of the JSON document. |
String |
getPointerToViolation()
A JSON pointer denoting the part of the document which violates the schema.
|
String |
getSchemaLocation() |
Schema |
getViolatedSchema() |
int |
getViolationCount() |
int |
hashCode() |
ValidationException |
prepend(String fragment)
Creates a new
ViolationException instance based on this one, but with changed
JSON pointer . |
ValidationException |
prepend(String fragment,
Schema violatedSchema)
Creates a new
ViolationException instance based on this one, but with changed
JSON pointer and {link violated
schema . |
static void |
throwFor(Schema rootFailingSchema,
List<ValidationException> failures)
Sort of static factory method.
|
org.json.JSONObject |
toJSON()
Creates a JSON representation of the failure.
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
@Deprecated public ValidationException(Class<?> expectedType, Object actualValue)
ValidationException(Schema, Class<?>, Object)
instead.expectedType
- the expected typeactualValue
- the violating valuepublic ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue)
keyword="type"
.violatedSchema
- the schema instance which detected the schema violationexpectedType
- the expected typeactualValue
- the violating value@Deprecated public ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword)
ValidationException(Schema, Class, Object)
instead.violatedSchema
- the schema instance which detected the schema violationexpectedType
- the expected typeactualValue
- the violating valuekeyword
- the violating keywordpublic ValidationException(Schema violatedSchema, Class<?> expectedType, Object actualValue, String keyword, String schemaLocation)
ValidationException(Schema, Class, Object)
instead.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@Deprecated public ValidationException(Schema violatedSchema, String message)
violatedSchema
- the schema instance which detected the schema violationmessage
- the readable exception message@Deprecated public ValidationException(Schema violatedSchema, String message, String keyword)
violatedSchema
- the schama instance which detected the schema violationmessage
- the readable exception messagekeyword
- the violated keywordpublic ValidationException(Schema violatedSchema, String message, String keyword, String schemaLocation)
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)@Deprecated public ValidationException(String message)
ValidationException(Schema, String)
instead.message
- readable exception message@Deprecated public ValidationException(Schema violatedSchema, String message, List<ValidationException> causingExceptions)
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 violatedSchemapublic static void throwFor(Schema rootFailingSchema, List<ValidationException> failures)
ObjectSchema
and ArraySchema
to
create ValidationException
s, handling the case of multiple violations occuring during
validation.
failures
is empty, then it doesn't do anythingfailures
contains 1 exception instance, then that will be thrownviolated schema
will be rootFailingSchema
, and its causing exceptions
will be the failures
listrootFailingSchema
- the schema which detected the failures
failures
- list containing validation failures to be thrown by this methodpublic List<ValidationException> getCausingExceptions()
public List<String> getAllMessages()
public String getMessage()
the pointer to the violating fragment
of the JSON document.getMessage
in class Throwable
public String getErrorMessage()
getMessage()
this doesn't
contain the JSON pointer denoting the violating document fragment.public String getPointerToViolation()
#
.public Schema getViolatedSchema()
public ValidationException prepend(String fragment)
ViolationException
instance based on this one, but with changed
JSON pointer
.fragment
- the fragment of the JSON pointer to be prepended to existing pointerspublic ValidationException prepend(String fragment, Schema violatedSchema)
ViolationException
instance based on this one, but with changed
JSON pointer
and {link violated
schema
.fragment
- the fragment of the JSON pointer to be prepended to existing pointersviolatedSchema
- the violated schema, which may not be the same as getViolatedSchema()
ViolationException
instancepublic int getViolationCount()
public String getKeyword()
public org.json.JSONObject toJSON()
The returned JSONObject
contains 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. See
getPointerToViolation()
"causingExceptions"
: is a (possibly empty) array of violations which caused this
exception. See getCausingExceptions()
"schemaLocation"
: a string denoting the path to the violated schema keyword in the schema
JSON (since version 1.6.0)public String getSchemaLocation()
Copyright © 2019 Everit Kft.. All rights reserved.