• Stars
    star
    358
  • Rank 114,572 (Top 3 %)
  • Language
    Java
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Module for generating JSON Schema (v3) definitions from POJOs

Jackson JSON Schema Module

This module supports the creation of a JSON Schema (v3)

Note that since JSON Schema draft version 3 and 4 are incompatible, this module CAN NOT, as-is, support v4. There is another module mbknor-jackson-jsonSchema that does support v4, however.

It is possible that in future this repo could have 2 different modules; one for v3, another v4. And if necessary, more if future revisions also prove incompatible.

Status

Build Status Maven Central Javadoc

Version 2.4 was considered the first stable version of the module.

Two modules (with Jackson 2.15)

Starting with upcoming Jackson 2.15, this repository contains TWO versions of the module:

  1. Old JSON Schema module com.fasterxml.jackson.module:jackson-module-jsonSchema (since 2.0)
  2. New JSON Schema module com.fasterxml.jackson.module:jackson-module-jsonSchema-jakarta (2.15+)

depending on whether system needs to work with "old" javax/JAXB APIs (first module) or newer "Jakarta" APIs.

Future plans (lack thereof)

Due to lack of support by community, this module is NOT planned to be supported beyond Jackson 2.x -- no work has been done for it to work with future Jackson 3.0. Users are encouraged to use more up-to-date JSON Schema support tools.

Example Usage

(from TestGenerateJsonSchema)

simply add a dependency "com.fasterxml.jackson.module:jackson-module-jsonSchema:2.15.0" or "com.fasterxml.jackson.module:jackson-module-jsonSchema-jakarta:2.15.0" for the jakarta namespace

and for gradle, at least, you can simply add mavenLocal() to your repositories. Maven should resolve the dependency from its local repo transparently.

ObjectMapper mapper = new ObjectMapper();
// configure mapper, if necessary, then create schema generator
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(SimpleBean.class);

This will yield a java pojo representing a JSON Schema, which can itself easily be serialized with jackson, or configured with java. Customizing the generation should be simply a matter of locating the particular stage of generation you want to override, and replacing or extending that particular object in the dependency injection cycle in schemafactory wrapper.

Adding Property Processing

See com.fasterxml.jackson.module.jsonSchema.customProperties.TitleSchemaFactoryWrapper for an example of writing custom schema properties.

Required Fields

JSON Schema has the ability to mark fields as required. This module supports this via the @JsonProperty(required = true) field annotation.

JsonSchema Hypermedia support

Generic support

Current implementation is partial for IETF published draft v4 (http://json-schema.org/latest/json-schema-hypermedia.html).

Currently 2 aspects of IETF supported:

  • pathStart - URI that defines what the instance's URI MUST start with in order to validate.
  • links - associated Link Description Objects with instances.

You can enable HypermediaSupport using com.fasterxml.jackson.module.jsonSchema.customProperties.HyperSchemaFactoryWrapper. Example:

HyperSchemaFactoryWrapper personVisitor = new HyperSchemaFactoryWrapper();
ObjectMapper mapper = new ObjectMapper();
mapper.acceptJsonFormatVisitor(Person.class, personVisitor);
JsonSchema personSchema = personVisitor.finalSchema();

By default all default values for Link Description Object are ignored in the output (method = GET, enctype = application/json, mediaType = application/json), to enable default setIgnoreDefaults(true)

Describing JSON hyper-schema

You can describe hyperlinks, using annotations @JsonHyperSchema & @Link

 public class Pet {
     public String genus;
 }

 @JsonHyperSchema(
     pathStart = "http://localhost:8080/persons/",
     links = {
         @Link(href = "{name}", rel = "self"),
         @Link(href = "{name}/pet", rel = "pet", targetSchema = Pet.class)
 })
 public class Person {
     public String name;
     public String hat;
 }

Would generate following values:

{
  "type" : "object",
  "pathStart" : "http://localhost:8080/persons/",
  "links" : [ {
    "href" : "http://localhost:8080/persons/{name}",
    "rel" : "self"
  }, {
    "href" : "http://localhost:8080/persons/{name}/pet",
    "rel" : "pet",
    "targetSchema" : {
      "type" : "object",
      "properties" : {
        "genus" : {
          "type" : "string"
        }
      }
    }
  } ],
  "properties" : {
    "name" : {
      "type" : "string"
    },
    "hat" : {
      "type" : "string"
    }
  }
}

More

Check out Project Wiki for more information (javadocs, downloads).

More Repositories

1

jackson

Main Portal page for the Jackson project
8,671
star
2

jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Java
3,429
star
3

jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Java
2,208
star
4

jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Kotlin
1,082
star
5

jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
Java
999
star
6

jackson-docs

Documentation for the Jackson JSON processor.
695
star
7

jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Java
550
star
8

jackson-module-scala

Add-on module for Jackson (https://github.com/FasterXML/jackson) to support Scala-specific datatypes
Scala
494
star
9

jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Java
392
star
10

jackson-dataformats-text

Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)
Java
383
star
11

jackson-datatype-hibernate

Add-on module for Jackson JSON processor which handles Hibernate (https://www.hibernate.org/) datatypes; and specifically aspects of lazy-loading
Java
307
star
12

jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Java
297
star
13

aalto-xml

Ultra-high performance non-blocking XML processor (Stax API + extensions)
Java
286
star
14

java-classmate

Library for introspecting generic type information of types, member/static methods, fields. Especially useful for POJO/Bean introspection.
Java
256
star
15

jackson-jr

Stand-alone data-binding module designed as a light-weight (and -featured) alternative to `jackson-databind`: will only deal with "Maps, Lists, Strings, wrappers and Java Beans" (jr-objects), or simple read-only trees (jr-stree)
Java
224
star
16

woodstox

The gold standard Stax XML API implementation. Now at Github.
Java
210
star
17

jackson-dataformat-csv

(DEPRECATED) -- moved under: https://github.com/FasterXML/jackson-dataformats-text
Java
194
star
18

jackson-modules-base

Uber-project for foundational modules of Jackson that build directly on core components but nothing else; not including data format or datatype modules
Java
163
star
19

jackson-dataformat-yaml

Jackson module to add YAML backend (parser/generator adapters)
Java
139
star
20

jackson-datatype-joda

Extension module to properly support full datatype set of Joda datetime library
Java
138
star
21

jackson-jaxrs-providers

Multi-module project that contains Jackson-based "old" JAX-RS (ones under `javax.ws.rs`) providers for JSON, XML, YAML, Smile, CBOR formats
Java
107
star
22

jackson-datatype-jsr310

(DEPRECATED) -- moved under `jackson-modules-java8` repo: https://github.com/FasterXML/jackson-modules-java8
Java
92
star
23

jackson-module-afterburner

(DEPRECATED) -- moved under `jackson-modules-base`
Java
91
star
24

smile-format-specification

New home for Smile format (https://en.wikipedia.org/wiki/Smile_(data_interchange_format))
87
star
25

jackson-datatypes-collections

Jackson project that contains various collection-oriented datatype libraries: Eclipse Collections, Guava, HPPC, PCollections
Java
73
star
26

jackson-datatype-guava

(DEPRECATED) -- moved under `jackson-datatypes-collections`
Java
68
star
27

jackson-datatype-jdk8

(DEPRECATED) -- moved under `jackson-modules-java8`
Java
58
star
28

jackson-datatype-json-org

(DEPRECATED) Support for org.json data types, to ease migration out of code that uses them
Java
50
star
29

jackson-bom

Bill of materials POM for Jackson projects
Logos
49
star
30

jackson-dataformat-smile

(DEPRECATED) -- moved under `jackson-dataformats-binary
Java
44
star
31

jackson-module-jaxb-annotations

(DEPRECATED!!!) Moved to: https://github.com/FasterXML/jackson-modules-base/
Java
43
star
32

StaxMate

StaxMate: Automatic Shifting for Streaming XML Processing
Java
41
star
33

jackson-dataformat-cbor

(DEPRECATED) -- moved under `jackson-dataformats-binary`
Java
38
star
34

jackson-dataformat-avro

(DEPRECATED) -- moved under `jackson-dataformats-binary
Java
38
star
35

stax2-api

Extension API for Stax, Java pull-parsing API (STreaming Api for Xml)
Java
36
star
36

jackson-module-parameter-names

(DEPRECATED) -- moved under `jackson-modules-java8`
Java
33
star
37

jackson-dataformat-protobuf

(DEPRECATED) -- moved under `jackson-dataformats-binary`
Java
32
star
38

jackson-module-mrbean

(DEPRECATED) -- moved under `jackson-modules-base`
Java
27
star
39

TransiStore

Distributed data store for transient (temporary, time-bound) data. Based on ClusterMate/StoreMate
Java
21
star
40

jackson-datatype-jsr353

(DEPRECATED) -- moved under `jackson-datatypes-misc` https://github.com/FasterXML/jackson-datatypes-misc/
Java
19
star
41

jackson-future-ideas

Repository for SOLE PURPOSE of issue tracker and Wiki for NEW IDEAS. Please: NO BUG REPORTS.
18
star
42

jackson-datatypes-misc

Collection of common Jackson datatype modules not part of other multi-project repos
Java
17
star
43

jackson-benchmarks

Project that contains JMH-based micro-benchmarks to help with optimizations
Java
14
star
44

jackson-dataformat-properties

(DEPRECATED) -- moved under `jackson-dataformats-text`
Java
13
star
45

jackson-jakarta-rs-providers

Multi-module project that contains Jackson-based "new" Jakarta-RS (nee "JAX-RS" -- ones under `jakarta.ws.rs`) providers for JSON, XML, YAML, Smile, CBOR formats
Java
10
star
46

jackson-datatype-hppc

(DEPRECATED) -- moved under `jackson-datatypes-collections`
Java
9
star
47

oss-parent

Grandpa pom for all projects under FasterXML git umbrella
8
star
48

jackson-datatype-jdk7

(DEPRECATED) -- included in `jackson-databind` as of Jackson 2.7
Java
7
star
49

jvm-json-benchmark

Performance benchmark suite that compares data-binding (JSON<->POJO) performance of Java JSON libraries. Uses Japex benchmark framework for running tests and visualizing results.
Java
7
star
50

Hacktoberfest2020

Central repository for FasterXML activities related to Hacktoberfest 2020 by DigitalOcean (https://hacktoberfest.digitalocean.com/)
6
star
51

jackson-module-guice

(DEPRECATED) -- moved under `jackson-modules-base`
Java
5
star
52

jackson3-dev

Repository for planning and tracking development of Jackson 3.0, with bigger API changes
5
star
53

jackson-module-paranamer

(DEPRECATED) -- moved under `jackson-modules-base`
Java
5
star
54

jackson-parent

Parent pom for all core Jackson components (but only those -- users should use `jackson-bom`)
5
star
55

jackson-schema-maven-plugin

Maven plug-in for generation JSON Schemas using Jackson library and extension modules
Java
4
star
56

jackson-jdk11-compat-test

Test project for verifying Jackson's support of JDK9+ Module system
Java
3
star
57

jackson-dataformat-thrift

Not Yet A Thing -- placeholder for possible future implementation
Java
3
star
58

jackson-integration-tests

Project that contains integration tests across Jackson components
Java
3
star
59

jackson-jdk17-compat-test

Test suite for JDK 16 compatibility of Jackson components, mainly jackson-databind
Java
3
star
60

jackson-tools

Collection of command-line tools related to Jackson data processor, such as format decoders
Java
2
star
61

jackson-dataformat-ini

(Not Yet a Thing -- Placholder!) Data format implementation for "ini files", used on Windows, Python
Java
2
star
62

jackson-jdk6-compat-test

Test project to verify JDK6 compatibility of Jackson versions 2.7 and anbove
Java
2
star
63

OmniPipe

Distributed data queue implementation that builds on ClusterMate/StoreMate foundation
2
star
64

jackson-module-osgi

(DEPRECATED) -- moved under `jackson-modules-base`
Java
2
star
65

jackson-gh-actions

Repository for reusable Github workflow actions for Jackson project
2
star
66

Woodstox4

Backup repository for older versions of Woodstox (pre-5.0), migrated from Codehaus
Java
1
star