JJSchema

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

com.github.reinert
ArtifactId

ArtifactId

jjschema
Last Version

Last Version

1.16
Release Date

Release Date

Type

Type

jar
Description

Description

JJSchema
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://github.com/reinert/JJSchema/
Source Code Management

Source Code Management

https://github.com/reinert/JJSchema

Download jjschema

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.reinert/jjschema/ -->
<dependency>
    <groupId>com.github.reinert</groupId>
    <artifactId>jjschema</artifactId>
    <version>1.16</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.reinert/jjschema/
implementation 'com.github.reinert:jjschema:1.16'
// https://jarcasting.com/artifacts/com.github.reinert/jjschema/
implementation ("com.github.reinert:jjschema:1.16")
'com.github.reinert:jjschema:jar:1.16'
<dependency org="com.github.reinert" name="jjschema" rev="1.16">
  <artifact name="jjschema" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.reinert', module='jjschema', version='1.16')
)
libraryDependencies += "com.github.reinert" % "jjschema" % "1.16"
[com.github.reinert/jjschema "1.16"]

Dependencies

compile (4)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-annotations jar 2.8.10
com.fasterxml.jackson.core : jackson-core jar 2.8.10
com.fasterxml.jackson.core : jackson-databind jar 2.8.10
javax.ws.rs : javax.ws.rs-api Optional jar 2.0.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

JJSchema

A Java JSON Schema and Hyper-Schema generator. Currently, it is based on v4 draft. Supports Java 8 Date and Time API.

Latest Release

<dependency>
  <groupId>com.github.reinert</groupId>
  <artifactId>jjschema</artifactId>
  <version>1.16</version>
</dependency>

Simple HOW TO

Suppose the following Class:

@Attributes(title="Product", description="A product from Acme's catalog")
static class Product {
	@Attributes(required=true, description="The unique identifier for a product")
	private long id;
	@Attributes(required=true, description="Name of the product")
	private String name;
	@Attributes(required=true, minimum=0, exclusiveMinimum=true)
	private BigDecimal price;
	@Attributes(minItems=1,uniqueItems=true)
	private List<String> tags;
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}	
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	public List<String> getTags() {
		return tags;
	}
	public void setTags(List<String> tags) {
		this.tags = tags;
	}
}

Type the following code:

JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory();
schemaFactory.setAutoPutDollarSchema(true);
JsonNode productSchema = schemaFactory.createSchema(Product.class);
System.out.println(productSchema);

The output:

{
  "type" : "object",
  "description" : "A product from Acme's catalog",
  "title" : "Product",
  "properties" : {
    "id" : {
      "type" : "integer",
      "description" : "The unique identifier for a product"
    },
    "name" : {
      "type" : "string",
      "description" : "Name of the product"
    },
    "price" : {
      "type" : "number",
      "minimum" : 0,
      "exclusiveMinimum" : true
    },
    "tags" : {
      "type" : "array",
      "items" : {
        "type" : "string"
      },
      "uniqueItems" : true,
      "minItems" : 1
    }
  },
  "required" : [ "id", "name", "price" ],
  "$schema" : "http://json-schema.org/draft-04/schema#"
}

Thanks to

IntelliJ

Versions

Version
1.16
1.15
1.14
1.13
1.12
1.11
1.10
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0
0.6
0.5.9
0.3
0.1