Skip to content

Instantly share code, notes, and snippets.

@agrawald
Created July 4, 2019 04:07
Show Gist options
  • Save agrawald/cc6d2cd5f68b2a69c26a7117226acd38 to your computer and use it in GitHub Desktop.
Save agrawald/cc6d2cd5f68b2a69c26a7117226acd38 to your computer and use it in GitHub Desktop.
Java POJO from JSON Schema using gradle
apply plugin: 'jsonschema2pojo'
// Each configuration is set to the default value
jsonSchema2Pojo {
// Whether to generate builder-style methods of the form withXxx(value) (that return this),
// alongside the standard, void-return setters.
generateBuilders = true
// Location of the JSON Schema file(s). This may refer to a single file or a directory of files.
source = files("${sourceSets.main.output.resourcesDir}/schema")
// Target directory for generated Java source files. The plugin will add this directory to the
// java source set so the compiler will find and compile the newly generated source files.
targetDirectory = file("${project.buildDir}/generated-sources")
// Package name used for generated Java classes (for types where a fully qualified name has not
// been supplied in the schema using the 'javaType' property).
targetPackage = 'au.nab.com.domain'
// Whether to include JSR-303/349 annotations (for schema rules like minimum, maximum, etc) in
// generated Java types. Schema rules and the annotation they produce:
// - maximum = @DecimalMax
// - minimum = @DecimalMin
// - minItems,maxItems = @Size
// - minLength,maxLength = @Size
// - pattern = @Pattern
// - required = @NotNull
// Any Java fields which are an object or array of objects will be annotated with @Valid to
// support validation of an entire document tree.
includeJsr303Annotations = true
initializeCollections = false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment