Skip to content

Instantly share code, notes, and snippets.

@mpellegrini
mpellegrini / JacksonJsonSchemaGenerator.java
Last active March 18, 2020 13:03
Generate JSON Schema using Jackson
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());