Skip to content

Latest commit

 

History

History
643 lines (623 loc) · 20 KB

parameters_5.adoc

File metadata and controls

643 lines (623 loc) · 20 KB

Extension jsonSchema2Pojo accepted parameters

Extension jsonSchema2Pojo is used to configure generator of Java POJO classes from JSON/YAML schema

Extension parameters

Extension allows to define target directory prefix and executions. Each execution defines parameters for Java POJOs generation using underlying library.

Table 1. Supported parameters
Name Type Default Description Notes

targetDirectoryPrefix

String

$buildDir/generated/sources/js2d

Directory property to define prefix under build directory where underlying tool will generate sources

executions

Set of named executions

Execution with parameters.

Execution name must follow the regular expression [a-z][A-Za-z0-9_]*.

Execution block parameters

Execution block specifies parameters listed below needed to process JSON schema to POJOs. All enum parameters are case-insensitive for a convenience.

Most of the parameters has defaults defined in jsonschema2pojo library.

All parameters and options listed are Gradle properties of given type. The only exception is source which is ConfigurableFileCollection.

Description and notes

Table 3. Supported parameters and options
Name Description Notes

annotationStyle

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

Supported values
  • jackson2 (apply annotations from the Jackson 2.x library)

  • jackson (alias for jackson2)

  • gson (apply annotations from the gson library)

  • moshi1 (apply annotations from the moshi 1.x library)

  • none (apply no annotations at all)

classNamePrefix

Whether to add a prefix to generated classes.

classNameSuffix

Whether to add a suffix to generated classes.

constructorsRequiredPropertiesOnly

This is a legacy configuration option and will be removed in subsequent releases. This option turns on the includeAllPropertiesConstructor parameter. This option turns off the constructorsIncludeAllPropertiesConstructor parameter.

This option will do nothing if constructors.generate parameter is not set to true ⚠️ This is the last release which includes this option.

customAnnotator

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

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

customDatePattern

A custom pattern to use when formatting date fields during serialization.

Requires support from your JSON binding library.

customDateTimePattern

A custom pattern to use when formatting date-time fields during serialization.

Requires support from your JSON binding library.

customRuleFactory

A fully qualified class name, referring to a class that extends org.jsonschema2pojo.rules.RuleFactory. This class will be used to create instances of Rules used for code generation.

customTimePattern

A custom pattern to use when formatting time fields during serialization.

Requires support from your JSON binding library.

dateTimeType

Which type to use instead of string when adding string type fields of format date-time to generated Java types.

dateType

Which type to use instead of string when adding string type fields of format date (not date-time) to generated Java types.

fileExtensions

The strings (no preceding dot) that should be considered as file name extensions, and therefore ignored, when creating Java class names.

fileFilter

List of file patterns to exclude.

This only applies to the initial scan of the file system. Option will not prevent inclusion through a "$ref" in one of the schemas.

formatDateTimes

Whether the fields of date type are formatted during serialization.

Default pattern is yyyy-MM-dd’T’HH:mm:ss.SSSZ as per JSON schema definition.

formatDates

Whether the fields of date type are formatted during serialization.

Default pattern is with a default pattern of yyyy-MM-dd as per JSON schema definition.

formatTimes

Whether the fields of time type are formatted during serialization.

Default pattern of HH:mm:ss.SSS as per JSON schema definition.

formatTypeMapping

Defines mapping from format identifier (e.g. 'uri') to fully qualified type name (e.g. 'java.net.URI').

generateBuilders

Whether to generate builder-style methods of the form withXxx(value) that return this, alongside the standard, void-return setters.

includeAdditionalProperties

Whether to allow 'additional properties' support in objects. Setting this to false will disable additional properties support, regardless of the input schema(s).

includeAllPropertiesConstructor

This option determines whether the resulting object should include a constructor with all listed properties as parameters.

This option will have no effect if includeConstructors is not set to true. This option is incompatible with constructorsRequiredPropertiesOnly.

includeConstructorPropertiesAnnotation

Whether to include JDK java.bean.ConstructorProperties. Used by some serialization libraries to get parameter names of constructors at runtime.

May not be available on Android

includeConstructors

Whether to generate constructors or not

⚠️ This is the last release which includes this option.

includeCopyConstructor

Generate copy constructor to assign all properties from the originating class to the new class.

This option works in collaboration with the includeConstructors configuration option. This option is incompatible with constructorsRequiredPropertiesOnly. This option will have no effect if includeConstructors is not set to true.

includeDynamicAccessors

Whether to include dynamic getters, setters, and builders or to omit these methods.

⚠️ This is the last release which includes this option.

includeDynamicBuilders

Whether to include dynamic builders or to omit these methods.

includeDynamicGetters

Whether to include dynamic getters or to omit these methods.

includeDynamicSetters

Whether to include dynamic setters or to omit these methods.

includeGeneratedAnnotation

Whether to mark generated classes with the Generated annotation.

It strongly depends on java version used to run POJO generator, not targetVersion.

includeGetters

Whether to include getters or to omit this accessor method and create public fields instead

includeHashcodeAndEquals

Whether to include hashCode and equals methods in generated Java types.

Note, that BigDecimal objects aren’t comparable by equals as expected.

includeJsr303Annotations

Whether to include JSR-303/349 annotations in generated Java types for various field constraints defined in schema. Any Java fields which are an object or array of objects will be annotated with @Valid to support validation.

Table 2. Schema rules and the annotation they produce
schema constraint annotation

maximum

@DecimalMax

minimum

@DecimalMin

minItems

@Size

maxItems

@Size

minLength

@Size

maxLength

@Size

pattern

@Pattern

required

@NotNull

includeJsr305Annotations

Whether to include JSR-305 annotations (for schema rules like Nullable, NonNull, etc.) in generated Java types.

includeRequiredPropertiesConstructor

This option determines whether the resulting object should include a constructor with only the required properties as parameters.

This option works in collaboration with the includeConstructors configuration option. This option is incompatible with constructorsRequiredPropertiesOnly. This option will have no effect if includeConstructors is not set to true.

includeSetters

Whether to include setters or to omit this accessor method and create public fields instead

includeToString

Whether to include a toString method in generated Java types.

includeTypeInfo

Whether to include json type information. This is often required to support polymorphic type handling. By default, the type information is stored in the @class property. This can be overridden in the deserializationClassProperty of the schema.

Works only if Jackson or Jackson2 were selected

inclusionLevel

The Level of inclusion to set in the generated Java types for Jackson serializers.

Supported values
  • ALWAYS NON_ABSENT

  • NON_DEFAULT

  • NON_EMPTY

  • NON_NULL

  • USE_DEFAULTS

Works only if Jackson or Jackson2 were selected

initializeCollections

Whether to initialize Set and List fields as empty collections, or leave them as null.

outputEncoding

The character encoding that should be used when writing the generated Java source files.

parcelable

Whether to make the generated types Parcelable.

Used for Android development.

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.

refFragmentPathDelimiters

A string containing any characters that should act as path delimiters when resolving $ref fragments. By default, #, / and . are used in an attempt to support JSON Pointer and JSON Path.

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.

serializable

Whether to make the generated types Serializable.

source

Location of the JSON Schema file(s).

this may refer to a single file or a directory of files.

sourceSortOrder

The sort order to be applied when recursively processing the source files. By default, the OS can influence the processing order.

Supported values
  • OS — Let the OS influence the order the source files are processed.

  • FILES_FIRST — Case sensitive sort, visit the files first. The source files are processed in a breadth first sort order.

  • SUBDIRS_FIRST — Case sensitive sort, visit the subdirectories before the files. The source files are processed in a depth first sort order.

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

  • yamlschema — JSON schema documents, represented as YAML

  • yaml — documents that represent an example of the kind of YAML (or JSON) data that the generated Java types will be mapped to

targetPackage

Package name prefix used for generated Java classes. This is used for types where a fully qualified name has not been supplied in the schema using the javaType property.

targetVersion

The target version for generated source files.

timeType

What type to use instead of string when adding string type fields of format time (not date-time) to generated Java types.

toStringExcludes

The fields to be excluded from toString generation

useBigDecimals

Whether to use the java type BigDecimal instead of float (or Float) when representing the JSON Schema type 'number'.

This parameter overrides useDoubleNumbers.

useBigIntegers

Whether to use the java type BigInteger instead of int (or Integer) when representing the JSON Schema type integer.

This parameter overrides useLongIntegers.

useDoubleNumbers

Whether to use the java type double (or Double) instead of float (or Float) when representing the JSON Schema type 'number'.

useInnerClassBuilders

If set to true, then the gang of four builder pattern will be used to generate builders on generated classes.

If the generateBuilders is false, then this property will not do anything.

useJodaDates

Whether to use org.joda.time.DateTime instead of Date when adding date type fields to generated Java types.

useJodaLocalDates

Whether to use org.joda.time.LocalDate instead of string when adding string type fields of format date to generated Java types.

useJodaLocalTimes

Whether to use org.joda.time.LocalTime instead of string when adding string type fields of format time to generated Java types.

useLongIntegers

Whether to use the java type long (or Long) instead of int (or Integer) when representing the JSON Schema type 'integer'.

useOptionalForGetters

Whether to use Optional as return type for getters of non-required fields.

usePrimitives

Whether to use primitives (long, double or boolean) instead of wrapper types where possible.

This has the side effect of making those properties non-null.

useTitleAsClassname

Use the title as class name. Otherwise, the property and file name is used.

Types and default values

Supported parameters and options (types and their defaults)
Name Type Default

annotationStyle

String

jackson2

classNamePrefix

String

classNameSuffix

String

constructorsRequiredPropertiesOnly

boolean

false

customAnnotator

String

org.jsonschema2pojo.NoopAnnotator

customDatePattern

String

customDateTimePattern

String

customRuleFactory

String

org.jsonschema2pojo.rules.RuleFactory

customTimePattern

String

dateTimeType

String

dateType

String

fileExtensions

List<String>

fileFilter

FileFilter

formatDateTimes

boolean

false

formatDates

boolean

false

formatTimes

boolean

false

formatTypeMapping

Map<String, String>

generateBuilders

boolean

false

includeAdditionalProperties

boolean

true

includeAllPropertiesConstructor

boolean

true

includeConstructorPropertiesAnnotation

boolean

false

includeConstructors

boolean

false

includeCopyConstructor

boolean

false

includeDynamicAccessors

boolean

false

includeDynamicBuilders

boolean

false

includeDynamicGetters

boolean

false

includeDynamicSetters

boolean

false

includeGeneratedAnnotation

boolean

false

includeGetters

boolean

true

includeHashcodeAndEquals

boolean

true

includeJsr303Annotations

boolean

false

includeJsr305Annotations

boolean

false

includeRequiredPropertiesConstructor

boolean

false

includeSetters

boolean

true

includeToString

boolean

true

includeTypeInfo

boolean

false

inclusionLevel

String

NON_NULL

initializeCollections

boolean

true

outputEncoding

String

UTF-8

parcelable

boolean

false

propertyWordDelimiters

String

- _

refFragmentPathDelimiters

String

#/.

removeOldOutput

boolean

false

serializable

boolean

source

ConfigurableFileCollection

$projectRoot/src/main/resources/json

sourceSortOrder

String

OS

sourceType

String

jsonschema

targetPackage

String

targetVersion

String

timeType

String

toStringExcludes

List<String>

useBigDecimals

boolean

false

useBigIntegers

boolean

false

useDoubleNumbers

boolean

true

useInnerClassBuilders

boolean

false

useJodaDates

boolean

false

useJodaLocalDates

boolean

false

useJodaLocalTimes

boolean

false

useLongIntegers

boolean

false

useOptionalForGetters

boolean

false

usePrimitives

boolean

false

useTitleAsClassname

boolean

false