This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
111c4c9
commit f872952
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [3.0.0] – 2019-06-10 | ||
### Added | ||
- Populate "description" as per `@JsonPropertyDescription` (falling-back on `@JsonClassDescription`). | ||
- Apply alternative field names defined in `@JsonProperty` annotations. | ||
- Ignore fields that are deemed to be ignored according to various `jackson-annotations` (e.g. `@JsonIgnore`, `@JsonIgnoreType`, `@JsonIgnoreProperties`) or are otherwise supposed to be excluded. | ||
|
||
[Unreleased]: https://github.com/victools/jsonschema-generator/compare/v3.0.0...HEAD | ||
[3.0.0]: https://github.com/victools/jsonschema-generator/releases/tag/v3.0.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# jsonschema-module-jackson | ||
Module for the jsonschema-generator – deriving JSON Schema attributes from jackson annotations | ||
# Java JSON Schema Generation – Module jackson | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.victools/jsonschema-module-jackson/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.victools/jsonschema-module-jackson) | ||
|
||
Module for the `jsonschema-generator` – deriving JSON Schema attributes from `jackson` annotations. | ||
|
||
## Features | ||
1. Populate "description" as per `@JsonPropertyDescription` (falling-back on `@JsonClassDescription`). | ||
2. Apply alternative field names defined in `@JsonProperty` annotations. | ||
3. Ignore fields that are deemed to be ignored according to various `jackson-annotations` (e.g. `@JsonIgnore`, `@JsonIgnoreType`, `@JsonIgnoreProperties`) or are otherwise supposed to be excluded. | ||
|
||
Schema attributes derived from validation annotations on getter methods are also applied to their associated fields. | ||
|
||
## Usage | ||
### Dependency (Maven) | ||
```xml | ||
<dependency> | ||
<groupId>com.github.victools</groupId> | ||
<artifactId>jsonschema-module-jackson</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
``` | ||
|
||
### Code | ||
#### Passing into SchemaGeneratorConfigBuilder.with(Module) | ||
```java | ||
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder; | ||
import com.github.victools.jsonschema.module.jackson.JacksonModule; | ||
``` | ||
```java | ||
JacksonModule module = new JacksonModule(); | ||
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper) | ||
.with(module); | ||
``` | ||
|
||
#### Complete Example | ||
```java | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.victools.jsonschema.generator.OptionPreset; | ||
import com.github.victools.jsonschema.generator.SchemaGenerator; | ||
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig; | ||
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder; | ||
import com.github.victools.jsonschema.module.jackson.JacksonModule; | ||
``` | ||
```java | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JacksonModule module = new JacksonModule(); | ||
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(objectMapper, OptionPreset.PLAIN_JSON) | ||
.with(module); | ||
SchemaGeneratorConfig config = configBuilder.build(); | ||
SchemaGenerator generator = new SchemaGenerator(config); | ||
JsonNode jsonSchema = generator.generateSchema(YourClass.class); | ||
|
||
System.out.println(jsonSchema.toString()); | ||
``` |
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