jsonschema2pojo:generate

Full name:

org.jsonschema2pojo:jsonschema2pojo-maven-plugin:0.4.27:generate

Description:

When invoked, this goal reads one or more JSON Schema documents and generates DTO style Java classes for data binding.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: compile.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: generate-sources.

Optional Parameters

Name Type Since Description
addCompileSourceRoot boolean 0.1.9 Add the output directory to the project as a source root, so that the generated java types are compiled and included in the project artifact.
Default value is: true.
annotationStyle String 0.3.1 The style of annotations to use in the generated Java types.

Supported values:

  • jackson2 (apply annotations from the Jackson 2.x library)
  • jackson1 (apply annotations from the Jackson 1.x library)
  • gson (apply annotations from the gson library)
  • moshi1 (apply annotations from the moshi 1.x library)
  • none (apply no annotations at all)

Default value is: jackson2.
classNamePrefix String 0.4.6 Whether to add a prefix to generated classes.
classNameSuffix String 0.4.6 Whether to add a suffix to generated classes.
constructorsRequiredPropertiesOnly boolean 0.4.8 Whether generated constructors should have parameters for all properties, or only required ones.
Default value is: false.
customAnnotator String 0.3.6 A fully qualified class name, referring to a custom annotator class that implements org.jsonschema2pojo.Annotator and will be used in addition to the one chosen by annotationStyle.

If you want to use the custom annotator alone, set annotationStyle to none.


Default value is: org.jsonschema2pojo.NoopAnnotator.
customRuleFactory String 0.4.5 A fully qualified class name, referring to an class that extends org.jsonschema2pojo.rules.RuleFactory and will be used to create instances of Rules used for code generation.
Default value is: org.jsonschema2pojo.rules.RuleFactory.
dateTimeType String 0.4.22 What type to use instead of string when adding string type fields of format date-time to generated Java types.
dateType String 0.4.22 What type to use instead of string when adding string type fields of format date (not date-time) to generated Java types.
excludes String[] 0.4.3 List of file patterns to exclude. This only applies to the initial scan of the file system and will not prevent inclusion through a "$ref" in one of the schemas.
fileExtensions String[] 0.4.23 The file extenations that should be considered as file name extensions, and therefore ignored, when creating Java class names.
generateBuilders boolean 0.1.2 Whether to generate builder-style methods of the form withXxx(value) (that return this), alongside the standard, void-return setters.
Default value is: false.
includeAccessors boolean 0.4.15 Whether to include getters/setters or to omit these accessor methods and create public fields instead.
Default value is: true.
includeAdditionalProperties boolean 0.4.14 Whether to allow 'additional properties' support in objects. Setting this to false will disable additional properties support, regardless of the input schema(s).
Default value is: true.
includeConstructors boolean 0.4.8 Whether to generate constructors or not
Default value is: false.
includeDynamicAccessors boolean 0.4.17 Whether to include dynamic getters, setters, and builders or to omit these methods.
Default value is: false.
includeHashcodeAndEquals boolean 0.3.1 Whether to include hashCode and equals methods in generated Java types.
Default value is: true.
includeJsr303Annotations boolean 0.3.2 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.
Default value is: false.
includeToString boolean 0.3.1 Whether to include a toString method in generated Java types.
Default value is: true.
includes String[] 0.4.3 List of file patterns to include.
initializeCollections boolean - Whether to initialize Set and List fields as empty collections, or leave them as null.
Default value is: true.
outputDirectory File 0.1.0 Target directory for generated Java source files.
Default value is: ${project.build.directory}/java-gen.
outputEncoding String 0.4.0 The character encoding that should be used when writing the generated Java source files.
Default value is: UTF-8.
parcelable boolean 0.4.11 **EXPERIMENTAL** Whether to make the generated types 'parcelable' (for Android development).
Default value is: false.
propertyWordDelimiters String 0.2.2 The characters that should be considered as word delimiters when creating Java Bean property names from JSON property names. If blank or not set, JSON properties will be considered to contain a single word when creating Java Bean property names.
Default value is: - _.
removeOldOutput boolean 0.3.7 Whether to empty the target directory before generation occurs, to clear out all source files that have been generated previously.

Be warned, when activated this option will cause jsonschema2pojo to indiscriminately delete the entire contents of the target directory (all files and folders) before it begins generating sources.


Default value is: false.
serializable boolean 0.4.23 Whether to make the generated types 'serializable'.
skip boolean 0.2.1 Skip plugin execution (don't read/validate any schema files, don't generate any java types).
Default value is: false.
sourceDirectory String 0.1.0 Location of the JSON Schema file(s). Note: this may refer to a single file or a directory of files.
sourcePaths String[] 0.3.1 An array of locations of the JSON Schema file(s). Note: each item may refer to a single file or a directory of files.
sourceType String 0.3.3 The type of input documents that will be read

Supported values:

  • jsonschema (schema documents, containing formal rules that describe the structure of json data)
  • json (documents that represent an example of the kind of json data that the generated Java types will be mapped to)

Default value is: jsonschema.
targetPackage String 0.1.0 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).
targetVersion String 0.4.17 The target version for generated source files.
Default value is: 1.6.
timeType String 0.4.22 What type to use instead of string when adding string type fields of format time (not date-time) to generated Java types.
useBigDecimals boolean 0.4.22 Whether to use the java type BigDecimal instead of float (or Float) when representing the JSON Schema type 'number'. Note that this configuration overrides isUseDoubleNumbers().
Default value is: false.
useBigIntegers boolean 0.4.25 Whether to use the java type BigInteger instead of int (or Integer) when representing the JSON Schema type 'integer'. Note that this configuration overrides isUseLongIntegers().
Default value is: false.
useCommonsLang3 boolean 0.4.1 Whether to use commons-lang 3.x imports instead of commons-lang 2.x imports when adding equals, hashCode and toString methods.
Default value is: false.
useDoubleNumbers boolean 0.4.0 Whether to use the java type double (or Double) instead of float (or Float) when representing the JSON Schema type 'number'.
Default value is: true.
useJodaDates boolean 0.4.0 Whether to use DateTime instead of Date when adding date type fields to generated Java types.
Default value is: false.
useJodaLocalDates boolean 0.4.9 Whether to use LocalDate instead of string when adding string type fields of format date (not date-time) to generated Java types.
Default value is: false.
useJodaLocalTimes boolean 0.4.9 Whether to use LocalTime instead of string when adding string type fields of format time (not date-time) to generated Java types.
Default value is: false.
useLongIntegers boolean 0.2.2 Whether to use the java type long (or Long) instead of int (or Integer) when representing the JSON Schema type 'integer'.
Default value is: false.
usePrimitives boolean 0.2.0 Whether to use primitives (long, double, boolean) instead of wrapper types where possible when generating bean properties (has the side-effect of making those properties non-null).
Default value is: false.

Parameter Details

addCompileSourceRoot:

Add the output directory to the project as a source root, so that the generated java types are compiled and included in the project artifact.
  • Type: boolean
  • Since: 0.1.9
  • Required: No
  • Expression: ${jsonschema2pojo.addCompileSourceRoot}
  • Default: true

annotationStyle:

The style of annotations to use in the generated Java types.

Supported values:

  • jackson2 (apply annotations from the Jackson 2.x library)
  • jackson1 (apply annotations from the Jackson 1.x library)
  • gson (apply annotations from the gson library)
  • moshi1 (apply annotations from the moshi 1.x library)
  • none (apply no annotations at all)
  • Type: java.lang.String
  • Since: 0.3.1
  • Required: No
  • Expression: ${jsonschema2pojo.annotationStyle}
  • Default: jackson2

classNamePrefix:

Whether to add a prefix to generated classes.
  • Type: java.lang.String
  • Since: 0.4.6
  • Required: No
  • Expression: ${jsonschema2pojo.classNamePrefix}

classNameSuffix:

Whether to add a suffix to generated classes.
  • Type: java.lang.String
  • Since: 0.4.6
  • Required: No
  • Expression: ${jsonschema2pojo.classNameSuffix}

constructorsRequiredPropertiesOnly:

Whether generated constructors should have parameters for all properties, or only required ones.
  • Type: boolean
  • Since: 0.4.8
  • Required: No
  • Expression: ${jsonschema2pojo.constructorsRequiredPropertiesOnly}
  • Default: false

customAnnotator:

A fully qualified class name, referring to a custom annotator class that implements org.jsonschema2pojo.Annotator and will be used in addition to the one chosen by annotationStyle.

If you want to use the custom annotator alone, set annotationStyle to none.

  • Type: java.lang.String
  • Since: 0.3.6
  • Required: No
  • Expression: ${jsonschema2pojo.customAnnotator}
  • Default: org.jsonschema2pojo.NoopAnnotator

customRuleFactory:

A fully qualified class name, referring to an class that extends org.jsonschema2pojo.rules.RuleFactory and will be used to create instances of Rules used for code generation.
  • Type: java.lang.String
  • Since: 0.4.5
  • Required: No
  • Expression: ${jsonschema2pojo.customRuleFactory}
  • Default: org.jsonschema2pojo.rules.RuleFactory

dateTimeType:

What type to use instead of string when adding string type fields of format date-time to generated Java types.
  • Type: java.lang.String
  • Since: 0.4.22
  • Required: No
  • Expression: ${jsonschema2pojo.dateTimeType}

dateType:

What type to use instead of string when adding string type fields of format date (not date-time) to generated Java types.
  • Type: java.lang.String
  • Since: 0.4.22
  • Required: No
  • Expression: ${jsonschema2pojo.dateType}

excludes:

List of file patterns to exclude. This only applies to the initial scan of the file system and will not prevent inclusion through a "$ref" in one of the schemas.
  • Type: java.lang.String[]
  • Since: 0.4.3
  • Required: No

fileExtensions:

The file extenations that should be considered as file name extensions, and therefore ignored, when creating Java class names.
  • Type: java.lang.String[]
  • Since: 0.4.23
  • Required: No
  • Expression: ${jsonschema2pojo.fileExtensions}

generateBuilders:

Whether to generate builder-style methods of the form withXxx(value) (that return this), alongside the standard, void-return setters.
  • Type: boolean
  • Since: 0.1.2
  • Required: No
  • Expression: ${jsonschema2pojo.generateBuilders}
  • Default: false

includeAccessors:

Whether to include getters/setters or to omit these accessor methods and create public fields instead.
  • Type: boolean
  • Since: 0.4.15
  • Required: No
  • Expression: ${jsonschema2pojo.includeAccessors}
  • Default: true

includeAdditionalProperties:

Whether to allow 'additional properties' support in objects. Setting this to false will disable additional properties support, regardless of the input schema(s).
  • Type: boolean
  • Since: 0.4.14
  • Required: No
  • Expression: ${jsonschema2pojo.includeAdditionalProperties}
  • Default: true

includeConstructors:

Whether to generate constructors or not
  • Type: boolean
  • Since: 0.4.8
  • Required: No
  • Expression: ${jsonschema2pojo.includeConstructors}
  • Default: false

includeDynamicAccessors:

Whether to include dynamic getters, setters, and builders or to omit these methods.
  • Type: boolean
  • Since: 0.4.17
  • Required: No
  • Expression: ${jsonschema2pojo.includeDynamicAccessors}
  • Default: false

includeHashcodeAndEquals:

Whether to include hashCode and equals methods in generated Java types.
  • Type: boolean
  • Since: 0.3.1
  • Required: No
  • Expression: ${jsonschema2pojo.includeHashcodeAndEquals}
  • Default: true

includeJsr303Annotations:

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.
  • Type: boolean
  • Since: 0.3.2
  • Required: No
  • Expression: ${jsonschema2pojo.includeJsr303Annotations}
  • Default: false

includeToString:

Whether to include a toString method in generated Java types.
  • Type: boolean
  • Since: 0.3.1
  • Required: No
  • Expression: ${jsonschema2pojo.includeToString}
  • Default: true

includes:

List of file patterns to include.
  • Type: java.lang.String[]
  • Since: 0.4.3
  • Required: No

initializeCollections:

Whether to initialize Set and List fields as empty collections, or leave them as null.
  • Type: boolean
  • Required: No
  • Expression: ${jsonschema2pojo.initializeCollections}
  • Default: true

outputDirectory:

Target directory for generated Java source files.
  • Type: java.io.File
  • Since: 0.1.0
  • Required: No
  • Expression: ${jsonschema2pojo.outputDirectory}
  • Default: ${project.build.directory}/java-gen

outputEncoding:

The character encoding that should be used when writing the generated Java source files.
  • Type: java.lang.String
  • Since: 0.4.0
  • Required: No
  • Expression: ${jsonschema2pojo.outputEncoding}
  • Default: UTF-8

parcelable:

**EXPERIMENTAL** Whether to make the generated types 'parcelable' (for Android development).
  • Type: boolean
  • Since: 0.4.11
  • Required: No
  • Expression: ${jsonschema2pojo.parcelable}
  • Default: false

propertyWordDelimiters:

The characters that should be considered as word delimiters when creating Java Bean property names from JSON property names. If blank or not set, JSON properties will be considered to contain a single word when creating Java Bean property names.
  • Type: java.lang.String
  • Since: 0.2.2
  • Required: No
  • Expression: ${jsonschema2pojo.propertyWordDelimiters}
  • Default: - _

removeOldOutput:

Whether to empty the target directory before generation occurs, to clear out all source files that have been generated previously.

Be warned, when activated this option will cause jsonschema2pojo to indiscriminately delete the entire contents of the target directory (all files and folders) before it begins generating sources.

  • Type: boolean
  • Since: 0.3.7
  • Required: No
  • Expression: ${jsonschema2pojo.removeOldOutput}
  • Default: false

serializable:

Whether to make the generated types 'serializable'.
  • Type: boolean
  • Since: 0.4.23
  • Required: No
  • Expression: ${jsonschema2pojo.serializable}

skip:

Skip plugin execution (don't read/validate any schema files, don't generate any java types).
  • Type: boolean
  • Since: 0.2.1
  • Required: No
  • Expression: ${jsonschema2pojo.skip}
  • Default: false

sourceDirectory:

Location of the JSON Schema file(s). Note: this may refer to a single file or a directory of files.
  • Type: java.lang.String
  • Since: 0.1.0
  • Required: No
  • Expression: ${jsonschema2pojo.sourceDirectory}

sourcePaths:

An array of locations of the JSON Schema file(s). Note: each item may refer to a single file or a directory of files.
  • Type: java.lang.String[]
  • Since: 0.3.1
  • Required: No
  • Expression: ${jsonschema2pojo.sourcePaths}

sourceType:

The type of input documents that will be read

Supported values:

  • jsonschema (schema documents, containing formal rules that describe the structure of json data)
  • json (documents that represent an example of the kind of json data that the generated Java types will be mapped to)
  • Type: java.lang.String
  • Since: 0.3.3
  • Required: No
  • Expression: ${jsonschema2pojo.sourceType}
  • Default: jsonschema

targetPackage:

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).
  • Type: java.lang.String
  • Since: 0.1.0
  • Required: No
  • Expression: ${jsonschema2pojo.targetPackage}

targetVersion:

The target version for generated source files.
  • Type: java.lang.String
  • Since: 0.4.17
  • Required: No
  • Expression: ${maven.compiler.target}
  • Default: 1.6

timeType:

What type to use instead of string when adding string type fields of format time (not date-time) to generated Java types.
  • Type: java.lang.String
  • Since: 0.4.22
  • Required: No
  • Expression: ${jsonschema2pojo.timeType}

useBigDecimals:

Whether to use the java type BigDecimal instead of float (or Float) when representing the JSON Schema type 'number'. Note that this configuration overrides isUseDoubleNumbers().
  • Type: boolean
  • Since: 0.4.22
  • Required: No
  • Expression: ${jsonschema2pojo.useBigDecimals}
  • Default: false

useBigIntegers:

Whether to use the java type BigInteger instead of int (or Integer) when representing the JSON Schema type 'integer'. Note that this configuration overrides isUseLongIntegers().
  • Type: boolean
  • Since: 0.4.25
  • Required: No
  • Expression: ${jsonschema2pojo.useBigIntegers}
  • Default: false

useCommonsLang3:

Whether to use commons-lang 3.x imports instead of commons-lang 2.x imports when adding equals, hashCode and toString methods.
  • Type: boolean
  • Since: 0.4.1
  • Required: No
  • Expression: ${jsonschema2pojo.useCommonsLang3}
  • Default: false

useDoubleNumbers:

Whether to use the java type double (or Double) instead of float (or Float) when representing the JSON Schema type 'number'.
  • Type: boolean
  • Since: 0.4.0
  • Required: No
  • Expression: ${jsonschema2pojo.useDoubleNumbers}
  • Default: true

useJodaDates:

Whether to use DateTime instead of Date when adding date type fields to generated Java types.
  • Type: boolean
  • Since: 0.4.0
  • Required: No
  • Expression: ${jsonschema2pojo.useJodaDates}
  • Default: false

useJodaLocalDates:

Whether to use LocalDate instead of string when adding string type fields of format date (not date-time) to generated Java types.
  • Type: boolean
  • Since: 0.4.9
  • Required: No
  • Expression: ${jsonschema2pojo.useJodaLocalDates}
  • Default: false

useJodaLocalTimes:

Whether to use LocalTime instead of string when adding string type fields of format time (not date-time) to generated Java types.
  • Type: boolean
  • Since: 0.4.9
  • Required: No
  • Expression: ${jsonschema2pojo.useJodaLocalTimes}
  • Default: false

useLongIntegers:

Whether to use the java type long (or Long) instead of int (or Integer) when representing the JSON Schema type 'integer'.
  • Type: boolean
  • Since: 0.2.2
  • Required: No
  • Expression: ${jsonschema2pojo.useLongIntegers}
  • Default: false

usePrimitives:

Whether to use primitives (long, double, boolean) instead of wrapper types where possible when generating bean properties (has the side-effect of making those properties non-null).
  • Type: boolean
  • Since: 0.2.0
  • Required: No
  • Expression: ${jsonschema2pojo.usePrimitives}
  • Default: false