Package org.apache.juneau.bean.jsonschema
Overview
Juneau supports serializing and parsing of JSON Schema documents through the use of beans defined in the
JsonSerializer
and
JsonParser
classes to produce and consume JSON Schema documents.
NOTE: This implementation follows the JSON Schema Draft 2020-12 specification. For backward compatibility, deprecated properties from earlier drafts (Draft 04) are still supported.
Bean Classes
The bean classes that make up the model are as follows:
JsonSchema
- Top level schema object.JsonSchemaProperty
- A subclass ofJsonSchema for representing properties.JsonSchemaPropertySimpleArray
- A convenience subclass ofJsonSchemaProperty for representing properties of simple array types.JsonSchemaRef
- Represents a URI reference to another schema.JsonSchemaArray
- An array ofJsonSchema objects.JsonType
- An enum of possible JSON data types.JsonTypeArray
- An array ofJsonType objects.
Creating JSON Schema Documents
JSON Schema documents can be constructed using the Juneau JSON Schema beans as a document model object. These beans are defined with fluent-style setters to make constructing documents as easy as possible.
The following is an example JSON Schema document:
{
This document can be constructed using the following code:
The following is a more-complex example showing various kinds of constraints:
{
This document can be constructed using the following code:
JsonSchema
Serializing to Other Data Types
Since the JSON Schema DTOs are simple beans, they can be used to serialize to a variety of other language types as well as JSON. This also allows JSON Schema documents to be easily served up using the Juneau REST API.
Parsing JSON Schema Documents
Use the JsonParser
to parse JSON Schema documents into DTOs:
Schema objects can also be constructed from other media types using the appropriate parsers.
See Also:
-
ClassDescriptionRepresents a top-level schema object bean in the JSON-Schema core specification.Used during parsing to convert the
additionalItems property to the correct class type.Used during parsing to convert theadditionalProperties property to the correct class type.Used during parsing to convert theitems property to the correct class type.Used during parsing to convert thetype property to the correct class type.Represents a list ofJsonSchema
objects.A container for retrieving JSONJsonSchema
objects by URI.Represents a JSON property in the JSON-Schema core specification.Convenience class for representing a property that's an array of simple types.Convenience class for representing a schema reference such as"{'$ref':'/url/to/ref'}" .Represents possible JSON types in the JSON-Schema core specification.Represents a list ofJsonType
objects.