Last active
March 18, 2020 13:03
-
-
Save mpellegrini/7571845 to your computer and use it in GitHub Desktop.
Generate JSON Schema using Jackson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws Exception { | |
ObjectMapper mapper = new ObjectMapper(); | |
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper); | |
JsonSchema jsonSchema = generator.generateSchema(Subscription.class); | |
StringWriter json = new StringWriter(); | |
mapper.configure(SerializationFeature.INDENT_OUTPUT, true); | |
mapper.writeValue(json, jsonSchema); | |
System.out.println(json.toString()); | |
} | |
/* | |
** Needs the following dependency ** | |
<dependency> | |
<groupId>com.fasterxml.jackson.module</groupId> | |
<artifactId>jackson-module-jsonSchema</artifactId> | |
<version>2.3.0</version> | |
</dependency> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to represent your input.json as a class with proper annotations (here is an example with a Subscription.class) and start this program.