Java JSON Schema Generator: https://github.com/victools/jsonschema-generator

Creates JSON Schema (Draft 6, Draft 7 or Draft 2019-09) from Java classes using Jackson.

Answer from Edgar Domingues on Stack Overflow
🌐
GitHub
github.com › victools › jsonschema-generator
GitHub - victools/jsonschema-generator: Java JSON Schema Generator – creating JSON Schema (Draft 6, Draft 7, Draft 2019-09, or Draft 2020-12) from Java classes
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON); SchemaGeneratorConfig config = configBuilder.build(); SchemaGenerator generator = new SchemaGenerator(config); JsonNode jsonSchema = generator.generateSchema(YourClass.class); System.out.println(jsonSchema.toPrettyString());
Starred by 535 users
Forked by 76 users
Languages   Java 74.4% | JavaScript 23.2% | SCSS 1.7%
🌐
Jsonschema2pojo
jsonschema2pojo.org
jsonschema2pojo
Generate Plain Old Java Objects from JSON or JSON-Schema. ... For each property present in the 'properties' definition, we add a property to a given Java class according to the JavaBeans spec.
🌐
Baeldung
baeldung.com › home › json › jackson › programmatic generation of json schemas in java
Programmatic Generation of JSON Schemas in Java | Baeldung
July 30, 2024 - Finally, the generated file name pattern is composed of {1} which is the package name and {0}, the class name. It will be located at src\main\resources\schemas\com\baeldung\jsonschemageneration\plugin\Person.json. To generate it, let’s run mvn compile. The resulting schema respects every condition specified in the plugin configuration. In this article, we’ve used Java JSON Schema Generator to generate JSON Schemas in Java.
🌐
JSON Type Definition
jsontypedef.com › docs › java-codegen
Generating Java from JSON Typedef schemas
“Properties” schemas will be converted into a Java POJO / Bean. Optional properties will be annotated with @JsonInclude(NON_NULL), which means that they will be omitted from JSON if set to null. Allowing “extra” properties will lead to the generated class being annotated with @JsonIngoreProperties:
🌐
JetBrains
plugins.jetbrains.com › plugin › 13733-pojo-to-json-schema
POJO to JSON Schema - IntelliJ IDEs Plugin | Marketplace
Generates JSON Schemas from Java classes. Generated json schemas locates under .generated-json-schemas folder. How to use Right click on Java class: Click POJO to JSON...
🌐
GitHub
github.com › FasterXML › jackson-module-jsonSchema
GitHub - FasterXML/jackson-module-jsonSchema: (DEPRECATED for Jackson 3) Module for generating JSON Schema (v3) definitions from POJOs
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 ...
Starred by 385 users
Forked by 137 users
Languages   Java 98.4% | Logos 1.3% | RPC 0.3% | Java 98.4% | Logos 1.3% | RPC 0.3%
🌐
GitHub
github.com › joelittlejohn › jsonschema2pojo
GitHub - joelittlejohn/jsonschema2pojo: Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc · GitHub
jsonschema2pojo generates Java types from JSON Schema (or example JSON) and can annotate those types for data-binding with Jackson 2.x, Jackson 3.x, or Gson.
Starred by 6.4K users
Forked by 1.7K users
Languages   Java 97.4% | Groovy 1.9%
Find elsewhere
Top answer
1 of 13
299

Try http://www.jsonschema2pojo.org

Or the jsonschema2pojo plug-in for Maven:

<plugin>
    <groupId>org.jsonschema2pojo</groupId>
    <artifactId>jsonschema2pojo-maven-plugin</artifactId>
    <version>1.0.2</version>
    <configuration>
        <sourceDirectory>${basedir}/src/main/resources/schemas</sourceDirectory>
        <targetPackage>com.myproject.jsonschemas</targetPackage>
        <sourceType>json</sourceType>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The <sourceType>json</sourceType> covers the case where the sources are json (like the OP). If you have actual json schemas, remove this line.

Updated in 2014: Two things have happened since Dec '09 when this question was asked:

  • The JSON Schema spec has moved on a lot. It's still in draft (not finalised) but it's close to completion and is now a viable tool specifying your structural rules

  • I've recently started a new open source project specifically intended to solve your problem: jsonschema2pojo. The jsonschema2pojo tool takes a json schema document and generates DTO-style Java classes (in the form of .java source files). The project is not yet mature but already provides coverage of the most useful parts of json schema. I'm looking for more feedback from users to help drive the development. Right now you can use the tool from the command line or as a Maven plugin.

2 of 13
22

If you're using Jackson (the most popular library there), try

https://github.com/astav/JsonToJava

Its open source (last updated on Jun 7, 2013 as of year 2021) and anyone should be able to contribute.

Summary

A JsonToJava source class file generator that deduces the schema based on supplied sample json data and generates the necessary java data structures.

It encourages teams to think in Json first, before writing actual code.

Features

  • Can generate classes for an arbitrarily complex hierarchy (recursively)
  • Can read your existing Java classes and if it can deserialize into those structures, will do so
  • Will prompt for user input when ambiguous cases exist
🌐
Victools
victools.github.io › jsonschema-generator
API Reference
The victools:jsonschema-generator aims at allowing the generation of JSON Schema (Draft 6, Draft 7, Draft 2019-09 or Draft 2020-12) to document Java code. This is expressly not limited to JSON but also allows for a Java API to be documented (i.e.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Create JSON Schema Automatically - Java Code Geeks
November 4, 2023 - By defining Java objects and utilizing annotations, developers can effortlessly generate JSON schemas from their Java classes.
🌐
Maven Repository
mvnrepository.com › artifact › com.github.victools › jsonschema-generator
Maven Repository: com.github.victools » jsonschema-generator
February 10, 2026 - Java JSON Schema Generator – creating a JSON Schema (Draft 6, Draft 7 or Draft 2019-09) from your Java classes
🌐
JetBrains
plugins.jetbrains.com › plugin › 26887-java-generate-json-schema
Java Generate Json Schema - IntelliJ IDEs Plugin | Marketplace
Generate JSON Schema from Java classes with support for nested objects, Javadoc comments, and customizable output formats. Compatible with IntelliJ 2024.3+.
🌐
Baeldung
baeldung.com › home › json › generate a java class from json
Generate a Java Class From JSON | Baeldung
May 11, 2024 - First, we’ll create a method convertJsonToJavaClass that converts a JSON file to a POJO class and accepts four parameters: ... Then, we’ll define the configuration for jsonschema2pojo, which lets the program identify that the input source file is JSON (the getSourceType method) Furthermore, we’ll pass this configuration to a RuleFactory, which will be used to create type generation rules for this mapping · We’ll create a SchemaMapper using this factory along with the SchemaGenerator object, which generates the Java type from the provided JSON
🌐
JetBrains
plugins.jetbrains.com › plugin › 22597-json-schema-generator
JSON Schema Generator - IntelliJ IDEs Plugin | Marketplace
This is a plugin for generating a sample JSON Schema from a JSON file. To generate a sample JSON Schema file, follow these steps: Once installed, go to Tools -&gt...
🌐
JSON Schema
json-schema.org › tools
JSON Schema - Tools
Toolings below are written in different languages, and support part, or all, of at least one recent version of the specification · Listing does not signify a recommendation or endorsement of any kind
🌐
GitHub
github.com › joelittlejohn › jsonschema2pojo › issues › 209
Generate JSON schema from Java class in Eclipse · Issue #209 · joelittlejohn/jsonschema2pojo
October 21, 2013 - This may be a little out of scope for this project but in a perfect world, it would be awesome if we could right click on a Java Class in eclipse and have a menu option that builds a stand alone JSON schema file from the class. It would ...
Published   Jun 26, 2014
🌐
NIST
pages.nist.gov › metaschema-java › metaschema-schema-generator › jacoco › gov.nist.secauto.metaschema.schemagen.json › JsonSchemaGenerator.java.html
JsonSchemaGenerator.java
*/ package gov.nist.secauto.me... properties.put("$schema", JsonNodeFactory.instance.objectNode() .put("type", "string") .put("format", "uri-reference")); ObjectNode rootObj = ObjectUtils.notNull(JsonNodeFactory.instance.objectNode()); state.getSchema(definition).generateSchemaOrRef(state, rootObj); properties.put(definition.getRootJsonName(), rootObj); return properties; } private static class RootPropertyEntry ...