-
- All Superinterfaces:
JsonSchemaReaderFactory
public interface JsonValidationService extends JsonSchemaReaderFactory
The facade interface for creating JSON validation objects.The following example shows how to read a JSON schema from a string:
JsonValidationService service = JsonValidationService.newInstance(); StringReader reader = new StringReader("{\"type\": \"integer\"}"); JsonSchema schema = service.readSchema(reader);Alternatively, a JSON schema can be built programmatically with
JsonSchemaBuilder.JsonSchemaBuilderFactory factory = service.createSchemaBuilderFactory(); JsonSchemaBuilder builder = factory.createBuilder(); JsonSchema schema = builder.withType(InstanceType.INTEGER).build();All the methods in this class are safe for use by multiple concurrent threads. For most use-cases, only one instance of JsonValidationService is required within the application.
- Author:
- leadpony
- See Also:
- Java API for JSON Processing (JSON-P), Java API for JSON Binding (JSON-B)
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description JsonProvidercreateJsonProvider(JsonSchema schema, ProblemHandlerFactory handlerFactory)Creates a JSON provider for validating JSON documents while parsing and reading.JsonParsercreateParser(InputStream in, Charset charset, JsonSchema schema, ProblemHandler handler)Creates a JSON parser from the specified byte stream, which validates the JSON document while parsing.JsonParsercreateParser(InputStream in, JsonSchema schema, ProblemHandler handler)Creates a JSON parser from the specified byte stream, which validates the JSON document while parsing.JsonParsercreateParser(Reader reader, JsonSchema schema, ProblemHandler handler)Creates a JSON parser from the specified character stream, which validates the JSON document while parsing.JsonParsercreateParser(Path path, JsonSchema schema, ProblemHandler handler)Creates a JSON parser from the specified path, which validates the JSON document while parsing.JsonParserFactorycreateParserFactory(Map<String,?> config)Creates a parser factory for creatingJsonParserinstances.JsonParserFactorycreateParserFactory(Map<String,?> config, JsonSchema schema, ProblemHandlerFactory handlerFactory)Creates a parser factory for creatingJsonParserinstances.ProblemHandlercreateProblemPrinter(Consumer<String> lineConsumer)Creates a problem handler which will print problems with the aid of the specified line consumer.ProblemHandlercreateProblemPrinter(Consumer<String> lineConsumer, Locale locale)Creates a problem handler which will print problems with the aid of the specified line consumer.ProblemPrinterBuildercreateProblemPrinterBuilder(Consumer<String> lineConsumer)Creates a builder instance which can be used to build a customized problem printer.JsonReadercreateReader(InputStream in, Charset charset, JsonSchema schema, ProblemHandler handler)Creates a JSON reader from a byte stream, which validates the JSON document while reading.JsonReadercreateReader(InputStream in, JsonSchema schema, ProblemHandler handler)Creates a JSON reader from a byte stream, which validates the JSON document while reading.JsonReadercreateReader(Reader reader, JsonSchema schema, ProblemHandler handler)Creates a JSON reader from a character stream, which validates the JSON document while reading.JsonReadercreateReader(Path path, JsonSchema schema, ProblemHandler handler)Creates a JSON reader from a path, which validates the JSON document while reading.JsonReaderFactorycreateReaderFactory(Map<String,?> config)Creates a reader factory for creatingJsonReaderinstances.JsonReaderFactorycreateReaderFactory(Map<String,?> config, JsonSchema schema, ProblemHandlerFactory handlerFactory)Creates a reader factory for creatingJsonReaderinstances.JsonSchemaBuilderFactorycreateSchemaBuilderFactory()Creates a factory for creating JSON schema builders.JsonSchemaReaderFactorycreateSchemaReaderFactory()Creates a factory for creating JSON schema readers with default configuration.JsonSchemaReaderFactoryBuildercreateSchemaReaderFactoryBuilder()Creates a builder for building a JSON schema reader factory.ValidationConfigcreateValidationConfig()Creates a configuration forJsonParserorJsonReaderwith validation functionality.JsonProvidergetJsonProvider()Returns the underlying JSON provider used by this service.static JsonValidationServicenewInstance()Creates a new instance of this type.default JsonSchemareadSchema(InputStream in)Reads a JSON schema from a byte stream.default JsonSchemareadSchema(InputStream in, Charset charset)Reads a JSON schema from a byte stream encoded by the specified charset.default JsonSchemareadSchema(Reader reader)Reads a JSON schema from a character stream.default JsonSchemareadSchema(Path path)Reads a JSON schema from a path.-
Methods inherited from interface org.leadpony.justify.api.JsonSchemaReaderFactory
createSchemaReader, createSchemaReader, createSchemaReader, createSchemaReader
-
-
-
-
Method Detail
-
newInstance
static JsonValidationService newInstance()
Creates a new instance of this type.- Returns:
- newly created instance of this type, never be
null. - Throws:
JsonException- if an error is encountered while creating the instance.
-
createSchemaReaderFactory
JsonSchemaReaderFactory createSchemaReaderFactory()
Creates a factory for creating JSON schema readers with default configuration.- Returns:
- newly created instance of JSON schema reader factory.
-
createSchemaReaderFactoryBuilder
JsonSchemaReaderFactoryBuilder createSchemaReaderFactoryBuilder()
Creates a builder for building a JSON schema reader factory.- Returns:
- newly created instance of JSON schema reader factory builder.
-
readSchema
default JsonSchema readSchema(InputStream in)
Reads a JSON schema from a byte stream. The character encoding of the stream is determined as described in RFC 7159.- Parameters:
in- the byte stream from which a JSON schema is to be read. The specified stream will be closed automatically in this method.- Returns:
- the read JSON schema.
- Throws:
NullPointerException- if the specifiedinisnull.JsonException- if an I/O error occurs while reading.JsonValidatingException- if the reader found problems during validation of the schema.
-
readSchema
default JsonSchema readSchema(InputStream in, Charset charset)
Reads a JSON schema from a byte stream encoded by the specified charset. The bytes of the stream will be decoded to characters using the specified charset.- Parameters:
in- the byte stream from which a JSON schema is to be read. The specified stream will be closed automatically in this method.charset- the character set.- Returns:
- the read JSON schema.
- Throws:
NullPointerException- if the specifiedinorcharsetisnull.JsonException- if an I/O error occurs while reading.JsonValidatingException- if the reader found problems during validation of the schema.
-
readSchema
default JsonSchema readSchema(Reader reader)
Reads a JSON schema from a character stream.- Parameters:
reader- the character stream from which a JSON schema is to be read. The specified reader will be closed automatically in this method.- Returns:
- the read JSON schema.
- Throws:
NullPointerException- if the specifiedreaderisnull.JsonException- if an I/O error occurs while reading.JsonValidatingException- if the reader found problems during validation of the schema.
-
readSchema
default JsonSchema readSchema(Path path)
Reads a JSON schema from a path.- Parameters:
path- the path from which a JSON schema is to be read.- Returns:
- the read JSON schema.
- Throws:
NullPointerException- if the specifiedpathisnull.JsonException- if an I/O error occurs while reading.JsonValidatingException- if the reader found problems during validation of the schema.
-
createSchemaBuilderFactory
JsonSchemaBuilderFactory createSchemaBuilderFactory()
Creates a factory for creating JSON schema builders.- Returns:
- the newly created instance of JSON schema builder factory.
- See Also:
JsonSchemaBuilderFactory
-
createValidationConfig
ValidationConfig createValidationConfig()
Creates a configuration forJsonParserorJsonReaderwith validation functionality. The map generated from the configuration can be passed to the methodscreateParserFactory(Map)andcreateReaderFactory(Map).- Returns:
- newly created configuration, never be
null.
-
createParserFactory
JsonParserFactory createParserFactory(Map<String,?> config)
Creates a parser factory for creatingJsonParserinstances. Parsers created by the factory can validate JSON documents while parsing.The factory is configured with the specified map of configuration properties.
Recommended way to create the configuration properties is to generate it via
ValidationConfig.getAsMap(). An instance ofValidationConfigcan be created by callingcreateValidationConfig().- Parameters:
config- the map of provider-specific properties to configure the JSON parsers. The map may be empty ornull.- Returns:
- newly created instance of
JsonParserFactory, which is defined in the JSON Processing API.
-
createParserFactory
JsonParserFactory createParserFactory(Map<String,?> config, JsonSchema schema, ProblemHandlerFactory handlerFactory)
Creates a parser factory for creatingJsonParserinstances. Parsers created by the factory validate JSON documents while parsing.The factory is configured with the specified map of configuration properties.
- Parameters:
config- the map of provider-specific properties to configure the JSON parsers. The map may be empty ornull.schema- the JSON schema to apply when validating JSON document.handlerFactory- the factory to supply problem handlers, cannot benull.- Returns:
- newly created instance of
JsonParserFactory, which is defined in the JSON Processing API. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createParser
JsonParser createParser(InputStream in, JsonSchema schema, ProblemHandler handler)
Creates a JSON parser from the specified byte stream, which validates the JSON document while parsing. The character encoding of the stream is determined as specified in RFC 7159.- Parameters:
in- the byte stream from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonParser, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.JsonException- if encoding cannot be determined or I/O error occurred.
-
createParser
JsonParser createParser(InputStream in, Charset charset, JsonSchema schema, ProblemHandler handler)
Creates a JSON parser from the specified byte stream, which validates the JSON document while parsing. The bytes of the stream are decoded to characters using the specified charset.- Parameters:
in- the byte stream from which JSON is to be read.charset- the character set.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonParser, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.JsonException- if encoding cannot be determined or I/O error occurred.
-
createParser
JsonParser createParser(Reader reader, JsonSchema schema, ProblemHandler handler)
Creates a JSON parser from the specified character stream, which validates the JSON document while parsing.- Parameters:
reader- the character stream from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonParser, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createParser
JsonParser createParser(Path path, JsonSchema schema, ProblemHandler handler)
Creates a JSON parser from the specified path, which validates the JSON document while parsing.- Parameters:
path- the path from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonParser, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
JsonException- if an I/O error occurs while creating parser.NullPointerException- if any of specified parameters isnull.
-
createReaderFactory
JsonReaderFactory createReaderFactory(Map<String,?> config)
Creates a reader factory for creatingJsonReaderinstances. Readers created by the factory can validate JSON documents while reading.The factory is configured with the specified map of configuration properties.
Recommended way to create the configuration properties is to generate it via
ValidationConfig.getAsMap(). An instance ofValidationConfigcan be created by callingcreateValidationConfig().- Parameters:
config- the map of provider specific properties to configure the JSON readers. The map may be empty ornull.- Returns:
- newly created instance of
JsonReaderFactory, which is defined in the JSON Processing API.
-
createReaderFactory
JsonReaderFactory createReaderFactory(Map<String,?> config, JsonSchema schema, ProblemHandlerFactory handlerFactory)
Creates a reader factory for creatingJsonReaderinstances. Readers created by the factory validate JSON documents while reading.The factory is configured with the specified map of configuration properties.
- Parameters:
config- the map of provider specific properties to configure the JSON readers. The map may be empty ornull.schema- the JSON schema to apply when validating JSON document.handlerFactory- the factory to supply problem handlers, cannot benull.- Returns:
- newly created instance of
JsonReaderFactory, which is defined in the JSON Processing API. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createReader
JsonReader createReader(InputStream in, JsonSchema schema, ProblemHandler handler)
Creates a JSON reader from a byte stream, which validates the JSON document while reading. The character encoding of the stream is determined as described in RFC 7159.- Parameters:
in- a byte stream from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonReader, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createReader
JsonReader createReader(InputStream in, Charset charset, JsonSchema schema, ProblemHandler handler)
Creates a JSON reader from a byte stream, which validates the JSON document while reading. The bytes of the stream are decoded to characters using the specified charset.- Parameters:
in- a byte stream from which JSON is to be read.charset- the character set.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonReader, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createReader
JsonReader createReader(Reader reader, JsonSchema schema, ProblemHandler handler)
Creates a JSON reader from a character stream, which validates the JSON document while reading.- Parameters:
reader- the character stream from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonReader, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createReader
JsonReader createReader(Path path, JsonSchema schema, ProblemHandler handler)
Creates a JSON reader from a path, which validates the JSON document while reading.- Parameters:
path- the path from which JSON is to be read.schema- the JSON schema to apply when validating JSON document.handler- the object which handles problems found during the validation, cannot benull.- Returns:
- newly created instance of
JsonReader, which is defined in the JSON Processing API. It must be closed by the method caller after use. - Throws:
JsonException- if an I/O error occurs while creating reader.NullPointerException- if any of specified parameters isnull.
-
createJsonProvider
JsonProvider createJsonProvider(JsonSchema schema, ProblemHandlerFactory handlerFactory)
Creates a JSON provider for validating JSON documents while parsing and reading. This method is intended to be used with Java API for JSON Binding (JSON-B).- Parameters:
schema- the JSON schema to apply when validating JSON document.handlerFactory- the factory to supply problem handlers, cannot benull.- Returns:
- newly created instance of
JsonProvider, which is defined in the JSON Processing API. - Throws:
NullPointerException- if any of specified parameters isnull.
-
createProblemPrinter
ProblemHandler createProblemPrinter(Consumer<String> lineConsumer)
Creates a problem handler which will print problems with the aid of the specified line consumer.If a customized printer is needed,
createProblemPrinterBuilder(Consumer)should be used instead of this method.- Parameters:
lineConsumer- the object which will output the message lines to somewhere.- Returns:
- newly created instance of problem handler.
- Throws:
NullPointerException- if the specifiedlineConsumerisnull.
-
createProblemPrinter
ProblemHandler createProblemPrinter(Consumer<String> lineConsumer, Locale locale)
Creates a problem handler which will print problems with the aid of the specified line consumer. The messages will be localized for the specified locale.If a customized printer is needed,
createProblemPrinterBuilder(Consumer)should be used instead of this method.- Parameters:
lineConsumer- the object which will output the message lines to somewhere.locale- the locale for which the problem messages will be localized.- Returns:
- newly created instance of problem handler.
- Throws:
NullPointerException- if the one of the specified parameters isnull.
-
createProblemPrinterBuilder
ProblemPrinterBuilder createProblemPrinterBuilder(Consumer<String> lineConsumer)
Creates a builder instance which can be used to build a customized problem printer.- Parameters:
lineConsumer- the object which will output the message lines to somewhere.- Returns:
- newly created instance of problem printer builder, which can be used to build a problem printer.
- Throws:
NullPointerException- if the specifiedlineConsumerisnull.
-
getJsonProvider
JsonProvider getJsonProvider()
Returns the underlying JSON provider used by this service.- Returns:
- the underlying JSON provider, never be
null.
-
-