Package io.github.microcks.util
Class JsonSchemaValidator
java.lang.Object
io.github.microcks.util.JsonSchemaValidator
Helper class for validating Json objects against their Json schema. Supported version of Json schema is
http://json-schema.org/draft-07/schema.
- Author:
- laurent
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.JsonNode
getJsonNode
(String jsonText) Get a Jackson JsonNode representation for Json object.static com.github.fge.jsonschema.main.JsonSchema
getSchemaNode
(String schemaText) Get a Jackson JsonNode representation for Json schema.static boolean
isJsonValid
(String schemaText, String jsonText) Check if a Json object is valid against the given Json schema specification.static boolean
isJsonValid
(String schemaText, String jsonText, String namespace) Check if a Json object is valid against the given Json schema specification.validateJson
(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode) Validate a Json object representing by its text against a schema object representing byt its text too.validateJson
(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode, String namespace) Validate a Json object representing by its text against a schema object representing byt its text too.validateJson
(String schemaText, String jsonText) Validate a Json object representing by its text against a schema object representing byt its text too.validateJson
(String schemaText, String jsonText, String namespace) Validate a Json object representing by its text against a schema object representing byt its text too.
-
Field Details
-
JSON_V4_SCHEMA_IDENTIFIER
- See Also:
-
JSON_V7_SCHEMA_IDENTIFIER
- See Also:
-
JSON_V12_SCHEMA_IDENTIFIER
- See Also:
-
JSON_SCHEMA_IDENTIFIER_ELEMENT
- See Also:
-
JSON_SCHEMA_COMPONENTS_ELEMENT
- See Also:
-
JSON_SCHEMA_PROPERTIES_ELEMENT
- See Also:
-
-
Method Details
-
isJsonValid
Check if a Json object is valid against the given Json schema specification.- Parameters:
schemaText
- The Json schema specification as a stringjsonText
- The Json object as a string- Returns:
- True if Json object is valid, false otherwise
- Throws:
IOException
- if json string representations cannot be parsed
-
isJsonValid
public static boolean isJsonValid(String schemaText, String jsonText, String namespace) throws IOException Check if a Json object is valid against the given Json schema specification.- Parameters:
schemaText
- The Json schema specification as a stringjsonText
- The Json object as a stringnamespace
- Namespace definition to resolve relative dependencies in Json schema- Returns:
- True if Json object is valid, false otherwise
- Throws:
IOException
- if json string representations cannot be parsed
-
validateJson
public static List<String> validateJson(String schemaText, String jsonText) throws IOException, com.github.fge.jsonschema.core.exceptions.ProcessingException Validate a Json object representing by its text against a schema object representing byt its text too. Validation is a deep one: its pursue checking children nodes on a failed parent. Validation is respectful of Json schema spec semantics regarding additional or unknown attributes: schema must explicitly setadditionalProperties
to false if you want to consider unknown attributes as validation errors. It returns a list of validation error messages.- Parameters:
schemaText
- The Json schema specification as a stringjsonText
- The Json object as a string- Returns:
- The list of validation failures. If empty, json object is valid !
- Throws:
IOException
- if json string representations cannot be parsedcom.github.fge.jsonschema.core.exceptions.ProcessingException
- if json node does not represent valid Schema
-
validateJson
public static List<String> validateJson(String schemaText, String jsonText, String namespace) throws IOException, com.github.fge.jsonschema.core.exceptions.ProcessingException Validate a Json object representing by its text against a schema object representing byt its text too. Validation is a deep one: its pursue checking children nodes on a failed parent. Validation is respectful of Json schema spec semantics regarding additional or unknown attributes: schema must explicitly setadditionalProperties
to false if you want to consider unknown attributes as validation errors. It returns a list of validation error messages.- Parameters:
schemaText
- The Json schema specification as a stringjsonText
- The Json object as a stringnamespace
- Namespace definition to resolve relative dependencies in Json schema- Returns:
- The list of validation failures. If empty, json object is valid !
- Throws:
IOException
- if json string representations cannot be parsedcom.github.fge.jsonschema.core.exceptions.ProcessingException
- if json node does not represent valid Schema
-
validateJson
public static List<String> validateJson(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode) throws com.github.fge.jsonschema.core.exceptions.ProcessingException Validate a Json object representing by its text against a schema object representing byt its text too. Validation is a deep one: its pursue checking children nodes on a failed parent. Validation is respectful of Json schema spec semantics regarding additional or unknown attributes: schema must explicitly setadditionalProperties
to false if you want to consider unknown attributes as validation errors. It returns a list of validation error messages.- Parameters:
schemaNode
- The Json schema specification as a Jackson nodejsonNode
- The Json object as a Jackson node- Returns:
- The list of validation failures. If empty, json object is valid !
- Throws:
com.github.fge.jsonschema.core.exceptions.ProcessingException
- if json node does not represent valid Schema
-
validateJson
public static List<String> validateJson(com.fasterxml.jackson.databind.JsonNode schemaNode, com.fasterxml.jackson.databind.JsonNode jsonNode, String namespace) throws com.github.fge.jsonschema.core.exceptions.ProcessingException Validate a Json object representing by its text against a schema object representing byt its text too. Validation is a deep one: its pursue checking children nodes on a failed parent. Validation is respectful of Json schema spec semantics regarding additional or unknown attributes: schema must explicitly setadditionalProperties
to false if you want to consider unknown attributes as validation errors. It returns a list of validation error messages.- Parameters:
schemaNode
- The Json schema specification as a Jackson nodejsonNode
- The Json object as a Jackson nodenamespace
- Namespace definition to resolve relative dependencies in Json schema- Returns:
- The list of validation failures. If empty, json object is valid !
- Throws:
com.github.fge.jsonschema.core.exceptions.ProcessingException
- if json node does not represent valid Schema
-
getJsonNode
public static com.fasterxml.jackson.databind.JsonNode getJsonNode(String jsonText) throws IOException Get a Jackson JsonNode representation for Json object.- Parameters:
jsonText
- The Json object as a string- Returns:
- The Jackson JsonNode corresponding to json object string
- Throws:
IOException
- if json string representation cannot be parsed
-
getSchemaNode
public static com.github.fge.jsonschema.main.JsonSchema getSchemaNode(String schemaText) throws IOException, com.github.fge.jsonschema.core.exceptions.ProcessingException Get a Jackson JsonNode representation for Json schema.- Parameters:
schemaText
- The Json schema specification as a string- Returns:
- The Jackson JsonSchema corresponding to json schema string
- Throws:
IOException
- if json string representation cannot be parsedcom.github.fge.jsonschema.core.exceptions.ProcessingException
- if json node does not represent valid Schema
-