Extension jsonSchema2Pojo
is used to configure generator of Java POJO classes from JSON/YAML schema.
Extension jsonSchema2Pojo
allows to define target directory prefix and executions.
Each execution defines parameters for Java POJOs generation using underlying library.
Name | Type | Default | Description | Notes |
---|---|---|---|---|
targetDirectoryPrefix |
String |
$buildDir/generated/sources/js2d |
Directory property to define prefix usually under build directory, where an underlying generator will produce sources. |
|
executions |
Set of named executions |
Execution with parameters. |
Execution name must follow the regular expression |
To add some executions, a developer should guide with Gradle User Guide.
-
Execution section must contain at least 1 execution and there can be as many as needed for a project.
-
Execution block specifies single set of parameters listed below needed to process a JSON schema into POJO(s).
-
Execution name must follow the regular expression
[a-z][A-Za-z0-9_]*
to generate task name properly. -
Each execution is processed independently and in the unknown order. User can define some task dependencies, but this won’t be done by the plugin.
-
All enum parameters are case-insensitive for a convenience.
-
Most of the parameters has defaults defined in
jsonschema2pojo
library.
All parameters have been split to simple categories as listed in the table below.
It’s possible to set options with a direct reference category.option.set(value)
or via block configuration category { option.set(value) }
as shown in the example below.
jsonSchema2Pojo {
executions {
create("main") {
// define block with settings for a given category
io {
source.setFrom(files("${projectDir}/schema"))
sourceType.set("yamlschema")
}
klass {
targetPackage.set("com.example")
annotationStyle.set("gson")
}
// configure a single field for a category
dateTime.jodaDate.set(false)
}
}
}
Category name | Meaning |
---|---|
|
These options tell which files to read and what encoding to produce. |
|
General class generation options. |
|
Options define how given class can be instantiated. |
|
Options to define which methods are created and which annotations are used. |
|
Options to define field type mapping (except date and time objects). |
|
Options to define date and time field generation and serialization. |
Name | Description | Notes |
---|---|---|
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. |
delimitersPropertyWord |
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. |
|
outputEncoding |
The character encoding that should be used when writing the generated Java source files. |
|
source |
Location of the JSON Schema file(s). |
this may refer to a single file or a directory of files. |
sourceType |
The type of input documents that will be read. Supported values
|
Value is case-insensitive |
sourceSortOrder |
The sort order to be applied when recursively processing the source files. By default, the OS can influence the processing order. Supported values
|
Value is case-insensitive |
targetJavaVersion |
The target Java version for generated source files. |
|
delimitersRefFragmentPath |
A string containing any characters that should act as path delimiters when resolving $ref fragments. Defaults are used in an attempt to support JSON Pointer and JSON Path. |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
delimitersPropertyWord |
String |
|
delimitersRefFragmentPath |
String |
|
fileExtensions |
List<String> |
|
fileFilter |
FileFilter |
|
outputEncoding |
String |
|
source |
ConfigurableFileCollection |
|
sourceSortOrder |
String |
|
sourceType |
String |
|
targetJavaVersion |
String |
Name | Description | Notes |
---|---|---|
androidParcelable |
Whether to make the generated types |
Used for Android development. |
annotateGenerated |
Whether to mark generated classes with the |
It strongly depends on java version used to run POJO generator, not |
annotateSerializable |
Whether to make the generated types |
|
annotationStyle |
The style of annotations to use in the generated Java types. Supported values
|
Value is case-insensitive |
customAnnotatorClass |
A fully qualified class name, referring to a custom annotator class that implements |
If you want to use the custom annotator alone, set |
customRuleFactoryClass |
A fully qualified class name, referring to a class that extends |
|
jackson2IncludeTypeInfo |
Whether to include json type information.
This is often required to support polymorphic type handling.
By default, the type information is stored in the |
Works only if |
jackson2InclusionLevel |
The Level of inclusion to set in the generated Java types for Jackson serializers. Supported values
|
|
namePrefix |
Whether to add a prefix to generated classes. |
|
nameSuffix |
Whether to add a suffix to generated classes. |
|
nameUseTitle |
Use the title as class name. Otherwise, the property and file name is used. |
|
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 |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
androidParcelable |
boolean |
false |
annotateGenerated |
boolean |
false |
annotateSerializable |
boolean |
|
annotationStyle |
String |
jackson2 |
customAnnotatorClass |
String |
org.jsonschema2pojo.NoopAnnotator |
customRuleFactoryClass |
String |
org.jsonschema2pojo.rules.RuleFactory |
jackson2IncludeTypeInfo |
boolean |
false |
jackson2InclusionLevel |
String |
NON_NULL |
namePrefix |
String |
|
nameSuffix |
String |
|
nameUseTitle |
boolean |
false |
targetPackage |
String |
Name | Description | Notes |
---|---|---|
allProperties |
This option determines whether the resulting object should include a constructor with all listed properties as parameters. |
|
annotateConstructorProperties |
Whether to include JDK |
May not be available on Android |
copyConstructor |
Generate copy constructor to assign all properties from the originating class to the new class. |
|
requiredProperties |
This option determines whether the resulting object should include a constructor with only the required properties as parameters. |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
allProperties |
boolean |
false |
annotateConstructorProperties |
boolean |
false |
copy |
boolean |
false |
requiredProperties |
boolean |
false |
Name | Description | Notes | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
additionalProperties |
Whether to allow 'additional properties' support in objects. Setting this to false will disable additional properties support, regardless of the input schema(s). |
|||||||||||||||||||
annotateJsr303 |
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.
|
|||||||||||||||||||
annotateJsr303Jakarta |
Whether to use |
Implies |
||||||||||||||||||
annotateJsr305 |
Whether to include JSR-305 annotations (for schema rules like Nullable, NonNull, etc.) in generated Java types. |
|||||||||||||||||||
builders |
Whether to generate builder-style methods of the form |
|||||||||||||||||||
buildersDynamic |
Whether to include dynamic builders. |
|||||||||||||||||||
buildersInnerClass |
If set to true, then the gang of four builder pattern will be used to generate builders on generated classes. |
Implies |
||||||||||||||||||
getters |
Whether to include getters or to omit this accessor method and create public fields instead. |
|||||||||||||||||||
gettersDynamic |
Whether to include dynamic getters. |
|||||||||||||||||||
gettersUseOptional |
Whether to use Optional as return type for getters of non-required fields. |
|||||||||||||||||||
hashcodeAndEquals |
Whether to include hashCode and equals methods in generated Java types. |
|
||||||||||||||||||
setters |
Whether to include setters or to omit this accessor method and create public fields instead. |
|||||||||||||||||||
settersDynamic |
Whether to include dynamic setters. |
|||||||||||||||||||
toStringExcludes |
The fields to be excluded from toString generation. |
|||||||||||||||||||
toStringMethod |
Whether to include a toString method in generated Java types. |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
additionalProperties |
boolean |
true |
annotateJakartaValidation |
boolean |
false |
annotateJsr303 |
boolean |
false |
annotateJsr305 |
boolean |
false |
builders |
boolean |
false |
buildersDynamic |
boolean |
false |
buildersInnerClass |
boolean |
false |
getters |
boolean |
true |
gettersDynamic |
boolean |
false |
gettersUseOptional |
boolean |
false |
hashcodeAndEquals |
boolean |
true |
setters |
boolean |
true |
settersDynamic |
boolean |
false |
toStringExcludes |
boolean |
true |
toStringMethod |
boolean |
false |
Name | Description | Notes |
---|---|---|
floatUseBigDecimal |
Whether to use the java type |
This parameter overrides |
floatUseDouble |
Whether to use the java type |
|
formatToTypeMapping |
Defines mapping from format identifier (e.g. 'uri') to fully qualified type name (e.g. 'java.net.URI'). |
|
initializeCollections |
Whether to initialize Set and List fields as empty collections, or leave them as null. |
|
integerUseBigInteger |
Whether to use the java type |
This parameter overrides |
integerUseLong |
Whether to use the java type |
|
usePrimitives |
Whether to use primitives ( |
This has the side effect of making those properties non-null. |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
floatUseBigDecimal |
boolean |
false |
floatUseDouble |
boolean |
true |
formatToTypeMapping |
|
|
initializeCollections |
boolean |
true |
integerUseBigInteger |
boolean |
false |
integerUseLong |
boolean |
false |
usePrimitives |
boolean |
false |
Name | Description | Notes |
---|---|---|
dateFormat |
How |
|
datePattern |
A custom pattern to use when formatting date fields during deserialization. |
Requires support from your JSON binding library. |
dateTimeFormat |
How |
|
dateTimePattern |
A custom pattern to use when formatting date-time fields during deserialization. |
Requires support from your JSON binding library. |
dateTimeType |
Which type to use instead of string when adding string type fields of format |
|
dateType |
Which type to use instead of string when adding string type fields of format |
|
jodaDate |
Whether to use |
|
jodaLocalDate |
Whether to use |
|
jodaLocalTime |
Whether to use |
|
timeFormat |
How |
|
timePattern |
A custom pattern to use when formatting time fields during deserialization. |
Requires support from your JSON binding library. |
timeType |
Which type to use instead of string when adding string type fields of format |
Supported parameters and options (types and their defaults)
Name | Type | Default |
---|---|---|
dateFormat |
String |
|
datePattern |
String |
|
dateTimeFormat |
String |
|
dateTimePattern |
String |
|
dateTimeType |
String |
|
dateType |
String |
|
jodaDate |
boolean |
false |
jodaLocalDate |
boolean |
false |
jodaLocalTime |
boolean |
false |
timeFormat |
String |
|
timePattern |
String |
|
timeType |
String |