Class | Description |
---|---|
JsonSchema |
Represents a top-level schema object bean in the JSON-Schema core specification.
|
JsonSchema.BooleanOrSchemaArraySwap |
Used during parsing to convert the
|
JsonSchema.BooleanOrSchemaSwap |
Used during parsing to convert the
|
JsonSchema.JsonSchemaOrSchemaArraySwap |
Used during parsing to convert the
|
JsonSchema.JsonTypeOrJsonTypeArraySwap |
Used during parsing to convert the
|
JsonSchemaArray |
Represents a list of
JsonSchema objects. |
JsonSchemaMap |
A container for retrieving JSON
JsonSchema objects by URI. |
JsonSchemaProperty |
Represents a JSON property in the JSON-Schema core specification.
|
JsonSchemaPropertySimpleArray |
Convenience class for representing a property that's an array of simple types.
|
JsonSchemaRef |
Convenience class for representing a schema reference such as
|
JsonTypeArray |
Represents a list of
JsonType objects. |
Schema | Deprecated
Use JsonSchema.
|
Schema.BooleanOrSchemaArraySwap |
Used during parsing to convert the
|
Schema.BooleanOrSchemaSwap |
Used during parsing to convert the
|
Schema.JsonTypeOrJsonTypeArraySwap |
Used during parsing to convert the
|
Schema.SchemaOrSchemaArraySwap |
Used during parsing to convert the
|
SchemaArray | Deprecated
Use JsonSchemaArray.
|
SchemaMap | Deprecated
Use JsonSchemaMap.
|
SchemaProperty | Deprecated
Use JsonSchemaProperty.
|
SchemaPropertySimpleArray | Deprecated
Use JsonSchemaPropertySimpleArray.
|
SchemaRef | Deprecated
Use JsonSchemaRef.
|
Enum | Description |
---|---|
JsonType |
Represents possible JSON types in the JSON-Schema core specification.
|
JSON-Schema Data Transfer Objects
Juneau supports serializing and parsing of JSON-Schema documents through the use of beans defined in the
org.apache.juneau.dto.jsonschema
package.
These beans are used with the existing JsonSerializer
and
JsonParser
classes to produce and consume JSON-Schema documents.
NOTE: JSON-Schema is currently in draft form. This API may change as the JSON-Schema specification changes.
The draft JSON-Schema specification that the JSON-Schema beans are modeled after is as follows:
{
The bean classes that make up the model are as follows:
JsonSchema
- Top level schema object.
JsonSchemaProperty
- A subclass of Schema
for
representing properties.
JsonSchemaPropertySimpleArray
- A convenience subclass of
SchemaProperty
for representing properties of simple array types.
JsonSchemaRef
- Represents a URI reference to another schema.
JsonSchemaArray
- An array of Schema
objects.
JsonType
- An enum of possible JSON data types.
JsonTypeArray
- An array of JsonType
objects.
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 constructing using the following code:
The following is a more-complex example showing various kinds of constraints.
{
This document can be constructing using the following code:
JsonSchema s =
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.
The sample web application includes a REST resource that generates a JSON-Schema document. We'll use this resource to show what the JSON-Schema document looks like in other languages.
When you point your browser to this resource, the default content type is HTML (since that's what the browser asks for by default).
The REST API allows you to specify the Accept
header as a GET parameter, and the
plainText=true
parameter forces the returned Content-Type
to be
text/plain
.
We'll use this to view the JSON-Schema document in other languages.
The full list of options for this resource can be accessed by the options
link on the HTML
page.
Use the JsonParser
to parse JSON-Schema documents into DTOs:
Schema objects can also be constructed from the other media types using the appropriate parsers.
*** fín ***
Copyright © 2018 Apache. All rights reserved.