Skip to content
Damian Malczewski edited this page Sep 13, 2026 · 2 revisions

FAQ

Why not Java records?

Records are a fine value carrier, but they give no builder, no defaults, no defensive copying of byte[] or List, and no control over constructor visibility - all of which ModelMaker emits. The generated class is what you would write by hand for a DTO that must stay immutable and bind from JSON.

Why is my enum a String?

Generated models support the simple types most likely to round-trip cleanly between a Java object and JSON. An enum becomes a String field plus a generated @Pattern over the allowed values, with a must be one of ... message. If you want a real Java enum, write it by hand and reference it with a $ref - see Property Types.

Can I reference my own hand-written type?

Only java.* and javax.* $ref targets are passed through as-is. Anything else must resolve to a schema title or a nested type name.

Should generated sources be checked in?

Not by default - generated sources go under build/generated, like any other build output. Set src { enabled = true } if you want them in the source tree, which some projects prefer because a schema change then shows up as a reviewable diff in the generated code. See Gradle Plugin.

Can I edit the generated code?

No. The output directory is deleted and rewritten on every run of the task.

Is there a Maven plugin?

No. The core generator has no build-tool dependency, so it can be driven from a Maven mojo, an Ant task or a plain main - see Library Usage - but only the Gradle plugin ships.

Does it support oneOf / allOf / anyOf, or maps?

No. The format is a small subset of JSON Schema aimed at flat, predictable DTOs. See Property Types.

Can two schemas reference each other?

Yes. $ref is resolved by name after all schemas are loaded, so cycles between top-level types are fine. Inline nested objects are expanded in place and therefore cannot recurse.

Why does an optional property with a default have no @Nullable?

Because it can never be null: the default is applied in the constructor. That also makes it eligible for preferPrimitives. See Schema Format.

Why is the constructor package-private with Jackson on?

So Jackson can bind straight through it, keeping the type immutable and skipping the builder. Without the jackson feature the constructor is private. See Jackson.

Does build() or Jackson validate my constraints?

Neither. build() only enforces that required properties were set, throwing NullPointerException; Jackson binds whatever the JSON contains, missing required properties included. A Validator has to run over the object, and whether that happens automatically is a property of the framework you are in - Spring Boot validates an annotated @RequestBody, a Kafka consumer or a batch job validates nothing. See Validation. range checks need a Validator - see Validation.

withers or mutate()?

withXyz(...) for a single field; mutate() when changing several at once, since it copies once rather than once per field. Kotlin callers get mutate { } as a DSL, see Kotlin Extensions.

Does Kotlin generation replace the Java DTOs?

No. kotlin { enabled = true } adds mutate { } extension functions next to the Java classes; the DTOs themselves are always Java.

Which Java version does the generated code need?

The output uses instanceof patterns and sealed interfaces, so Java 17 or newer.

Can I apply the plugin to a module that has no schemas?

Yes. A missing or empty schema directory is not an error - the tasks log No model schemas found in ... and generate nothing, which makes the plugin safe to apply from a convention plugin across a multi-module build.

Why is there no @Generated annotation on the generated types?

Because javax.annotation.processing.Generated lives in the java.compiler module, so every consumer with a module-info.java would have to requires java.compiler for generated code to compile. The do-not-edit banner at the top of each file carries the same information at no cost.

How do I keep a password out of the logs?

Mark the property "sensitive": true and its value is masked as *** in the generated toString(), see Schema Format.

Can I put schemas in subdirectories?

Yes - the schema directory is scanned recursively. The package comes from title, not from the directory layout. The directory itself is configurable, see Gradle Plugin.

Why is a generated line 200 characters long?

Some annotations - @Schema with a long description, container-element constraints on a List - are emitted on one line by design. Exclude the generated directory from your formatter rather than reflowing it.

Clone this wiki locally