Skip to content

Examples

Damian Malczewski edited this page Sep 10, 2026 · 2 revisions

Examples

The repository ships standalone Gradle builds under examples/, each applying the plugin from mavenLocal(). They are not part of the root build - they are consumers, exercising the published plugin the way a real project would.

Running them

./gradlew publishToMavenLocal   # publish the plugin and core to ~/.m2
examples/buildAll build         # run `build` in every example

examples/buildAll <tasks> forwards its arguments to each example's own wrapper, so examples/buildAll clean build or examples/buildAll generateModelJava work too. A single example can be built on its own:

cd examples/example-validation
./gradlew build

What each one shows

  • example-jackson - the jackson feature against Jackson 3 (tools.jackson), plus Kotlin mutate. Includes a round-trip test.
  • example-validation - the validation feature and jakarta.validation constraints, with a Hibernate Validator test.
  • example-openapi - jackson + validation + openApi on one type: OpenAPI @Schema alongside the other two.
  • example-mutator - Kotlin mutate { } extensions, including one for a nested type.

example-jackson

Seven schemas covering the shape of the format: a simple two-field type, a nested object, a nested list of objects, one of every scalar type, and enum-as-pattern. The test deserializes JSON into the generated DTOs and serializes back, so the @JsonCreator constructor and @JsonProperty names are actually exercised.

example-validation

@NotNull, @Pattern, @Email, @Min / @Max and @Size on one type; @Valid cascading into a nested object; and a list where the elements carry their own constraints while minItems / maxItems size the list. The test runs a real Validator and asserts on the violations.

example-openapi

A Customer with description and example on its properties, requiredMode on the required ones, and the facets left to jakarta.validation - the arrangement described on OpenAPI.

example-mutator

The Kotlin plugin applied, kotlin { enabled = true }, and the generated <Name>Extensions.kt checked in next to the Java. Kit holds a $ref to Widget, showing that each type gets its own extension.

Reading the generated output

Each example uses the default src.enabled = true, so the generated code is checked into the repository under src/main/model/java (and src/main/model/kotlin). Read it side by side with the schema in src/main/model - it is the fastest way to see what a keyword does:

examples/example-openapi/src/main/model/
├── com.example.dto.Customer.json          ← schema
└── java/com/example/dto/Customer.java     ← what it generates

The examples also show the surrounding build conventions worth copying - a Java 25 toolchain compiling options.release = 17, -parameters, and Spotless with the generated directory excluded:

spotless {
    java {
        target("src/**/*.java")
        targetExclude("build/**", "src/main/model/java/**")
    }
}

Clone this wiki locally