The document discusses using a JSON Schema validator in Mule to validate JSON payloads against a referenced JSON schema. The validator can match against local or external schemas, and if validation fails it will raise an exception with details. It supports schema draft versions 4 and older and can handle various payload types, attempting to transform if needed. The document provides information on configuration properties, validation behavior, and precautions when the payload type is a stream.
3. JSON Schema Validator
JSON schema validator is used to validate JSON data against a JSON schema.
The JSON Schema validator evaluates JSON payloads at runtime and verifies
that they match a referenced JSON schema. You can match against schemas
that exist in a local file or in an external URI. If the validation fails, an exception
is raised with feedback about what went wrong and a reference to the original
invalid payload. The JSON Schema Validator supports schema drafts of
version 4 and older.
4. Accepted Payload Types
java.lang.String, java.io.Reader, InputStream, byte[],
com.fasterxml.jackson.databind.JsonNode, org.mule.module.json.JsonData
If the payload type is none of the above, then the validator attempts to
transform the payload into a usable type, in the following order:
org.mule.module.json.JsonData
com.fasterxml.jackson.databind.JsonNode
java.lang.String
5. ConfigurationFollowing are the properties on general tab:
Display Name – The display name of the connector used for display purposes in
Mule flow.
Schema Location – Location of the schema. It may be a web URL, file system
URL etc.
Dereferencing - Draft v4 defines two dereferencing modes, canonical (default)
and inline. This attribute is ignored if validating a v3 draft.
Schema redirects - Schema Validator supports referencing URIs to external
schemas, and because one schema might reference another, the validator
also supports URI redirection, so that a reference to another schema doesn’t
6. Schema Redirects
In this example, any links to the external address
http://my.site/schemas/fstab.json will redirect to the internal address
resource:/org/mule/json/examples/fstab.json.
7. Validation Behavior
If the validation is successful, then control is passed to the next processor in
the chain. Otherwise a JsonSchemaValidationException is thrown
containing validation feedback on the message. This exception contains a
message with a detailed explanation of what went wrong, and a property
called invalidJson in which the invalid payload is available on its String
representation.
8. Precaution
For performing validation the validator consumes a streaming resource
(InputStream, Reader, etc), so the message payload is altered to the fully
consumed JSON.
So you may pass a payload of type java.io.InputStream or a java.io.Reader
but you may get back a String