Skip to content

Feature Configuration

Damian Malczewski edited this page Sep 10, 2026 · 1 revision

Feature Configuration

Five features decide what ends up on a generated class. All of them are off by default - out of the box you get a plain immutable POJO with no third-party annotations.

  • jackson - { enabled, annotateFields, annotateGetters, includeNonNull }. Adds @JsonCreator, @JsonProperty, @JsonPropertyOrder and @JsonIgnoreProperties, plus @JsonInclude(NON_NULL) when includeNonNull is on.
  • validation - { enabled, annotateFields, annotateGetters }. Adds jakarta.validation constraints and @Valid cascades.
  • openApi - { enabled, annotateFields, annotateGetters }. Adds OpenAPI @Schema metadata.
  • withers - { enabled }. Adds a withXyz(value) single-field copy method per property.
  • preferPrimitives - { enabled }. Uses int / double / boolean instead of boxed types where the property can never be null.

withers and preferPrimitives are covered on Generated Java Code.

Defaults

Setting Default
enabled false
annotateFields false
annotateGetters true

So an enabled annotation feature annotates the getters.

Three levels of configuration

Resolved highest priority first:

  1. Per schema file - a top-level "features" object in the schema.
  2. Per task - a features { } block on generateModelJava.
  3. Project-wide - modelmaker { features { } } in the build script.

Anything left unspecified at a level falls through to the next one, key by key - a schema that sets only jackson.enabled keeps the project's annotateGetters.

Project-wide

modelmaker {
    features {
        jackson {
            enabled = true
            annotateFields = false
            annotateGetters = true
            includeNonNull = false
        }
        validation { enabled = true }
        openApi { enabled = true }
        withers { enabled = false }
        preferPrimitives { enabled = false }
    }
}

Per task

tasks.named<JavaModelGenerate>("generateModelJava") {
    features {
        withers { enabled = true }
    }
}

Per schema file

{
  "$modelmaker": "v1.0",
  "title": "com.example.dto.Person",
  "type": "object",
  "properties": { "id": { "type": "string" } },
  "features": {
    "jackson": { "enabled": true },
    "validation": { "enabled": true, "annotateFields": true, "annotateGetters": false },
    "withers": { "enabled": true }
  }
}

Each entry is an object matching the DSL shape, not a bare boolean. "jackson": true is rejected, as is an unknown feature name or an unknown key inside a feature.

Annotation placement

annotateFields and annotateGetters decide where a feature's annotations sit. They are independent, so three useful combinations exist:

annotateFields annotateGetters Result
false true Getters only. The default.
true false Fields only.
true true Both.

Setting both to false while enabled = true leaves the feature with nowhere to emit, which is almost certainly a mistake.

Warning

Annotating both sites with validation means Hibernate Validator visits every constraint twice - each violation is reported twice.

Container-element annotations (a List's element constraints and the @Valid cascade into a list of generated types) render at the same site as the property's own constraints. The constructor and the builder always keep the plain List<T>.

Choosing features

  • DTOs bound from JSON - jackson.
  • Constraints enforced at runtime - validation.
  • Contract metadata in generated API docs - openApi, usually alongside jackson and validation.
  • Ergonomic single-field copies - withers.
  • No boxing for always-present numbers - preferPrimitives.
  • A Kotlin mutate { } DSL - kotlin { enabled = true }. Not a feature flag, see Kotlin Extensions.

Each annotation feature needs its library on the consumer's compile classpath; ModelMaker emits the annotations but brings no dependencies. See Getting Started.

Clone this wiki locally