json-schema

json-schema generator for the JVM.

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.mercateo
ArtifactId

ArtifactId

json-schema
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

json-schema
json-schema generator for the JVM.
Project URL

Project URL

https://github.com/mercateo/json-schema
Source Code Management

Source Code Management

https://github.com/mercateo/json-schema

Download json-schema

How to add to project

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

Dependencies

runtime (7)

Group / Artifact Type Version
com.googlecode.gentyref : gentyref jar 1.2.0
com.fasterxml.jackson.core : jackson-annotations jar 2.11.4
com.fasterxml.jackson.core : jackson-databind jar 2.11.4
org.slf4j : slf4j-api jar 1.7.30
javax.validation : validation-api jar 2.0.1.Final
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.32
org.jetbrains.kotlin : kotlin-reflect jar 1.4.32

test (8)

Group / Artifact Type Version
junit : junit jar 4.13
org.assertj : assertj-core jar 3.16.1
io.mockk : mockk jar 1.10.0
org.openjdk.jmh : jmh-core jar 1.25
org.openjdk.jmh : jmh-generator-annprocess jar 1.25
ch.qos.logback : logback-classic jar 1.2.3
org.jetbrains.kotlin : kotlin-test jar 1.4.32
org.hibernate : hibernate-validator jar 6.1.5.Final

Project Modules

There are no modules declared in this project.

json-schema

Codacy Badge Build Status Coverage Status MavenCentral

Generic JSON-Schema generator.

Features

  • Handles Generics
  • Configurable
  • Supports dynamic schema with allowed values and default values

Example

    SchemaGenerator schemaGenerator = new SchemaGenerator(
            Collections.emptyList(),
            Collections.<RawPropertyCollector>singletonList(new FieldCollector()),
            new HashMap<>());
    
    ObjectNode schema = schemaGenerator.generateSchema(Foo.class);
    
    String schemaString = schema.toString();

Generates the following result:

{
  "type": "object", 
  "properties": {
    "baz": {
      "type": "object", 
      "properties": {
        "qux": {
          "type": "string"
        }
      }
    }, 
    "bar": {
      "type": "string"
    }
  }
}}

Property structure

class Foo {
    String bar;
    Baz baz;
}

class Baz {
    String qux;
}

bar, baz and qux are properties.

Property representation

Properties are represented as Property Objects specified by containing and contained type:

Property<Foo, String> bar;
Property<Foo, Baz> baz;
Property<Baz, String> qux;

The part of the property which is represented by its type is contained in a PropertyDescriptor which has a generic type representing its contained type.

Property unwrapping

class Foo {
    String bar;
    
    @JsonUnwrapped
    Baz baz;
}

class Baz {
    String qux;
}
Property<Foo, String> bar;
Property<Foo, String> qux;

Benchmarks

current results

Benchmark                         Mode  Cnt        Score       Error  Units
Benchmarks.createRepeatedSchema  thrpt   10  1818545.697 ± 38533.578  ops/s
Benchmarks.createSchema          thrpt   10   260946.251 ± 15201.070  ops/s

createSchema creates SchemaGenerator and schema for each iteration, createdRepeatedSchema uses caching in the SchemaGenerator for schema creation

com.mercateo
the procurement platform for your business

Versions

Version
0.2.0
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0