Type Mapping
How OpenAPI schema types and formats map to Java types, and how to override the mapping globally or per property.
Primitive mapping
A scalar model field that is required and not
nullable: true is guaranteed present and non-null, so the generator emits the Java
primitive form rather than the boxed wrapper:
Driver:
required: [id, version, logbookUser]
properties:
id: { type: integer, format: int64 } # required -> long
version: { type: integer } # required -> int
logbookUser: { type: boolean } # required -> boolean
tag: { type: integer } # optional -> Integer
public record Driver(
long id,
int version,
boolean logbookUser,
@Nullable Integer tag
) {}
Only the wrapper types Boolean, Integer, Long,
Double and Float are unboxed. A field that is required
and nullable: true stays boxed (it can be explicitly null).
Parameters with a default are also unboxed — see
Parameter defaults.
This makes generated DTOs match hand-written records that use primitives for mandatory fields.
To get a byte-exact match also consider generateValidationAnnotations=false (see
DTO Models).
Date and time types
OpenAPI's format: date-time (RFC 3339) carries a timezone offset, so it maps to
java.time.OffsetDateTime by default. Set the global dateTimeType to
change the type used for all format: date-time properties:
<dateTimeType>INSTANT</dateTimeType>
<!-- INSTANT | OFFSET_DATE_TIME (default) | LOCAL_DATE_TIME | ZONED_DATE_TIME -->
format: date always maps to java.time.LocalDate.
Per-property overrides
Three mechanisms override the global default for an individual property. Precedence, highest first:
-
x-java-typevendor extension — keeps the spec standard and accepts any fully qualified class name:externalLastModified: type: string format: date-time x-java-type: java.time.OffsetDateTime -
Extended
formatvalues — concise shorthand for the commonjava.timetypes:format:valueJava type instantjava.time.Instantoffset-date-timejava.time.OffsetDateTimelocal-date-timejava.time.LocalDateTimezoned-date-timejava.time.ZonedDateTime - Global
dateTimeType— applied to plainformat: date-time.
Global type mappings
typeMappings overrides the Java type generated for a schema format or
type, without editing each schema. Keys are a schema format (e.g.
uuid, date-time, binary) or a bare type (e.g.
string); values are fully-qualified Java type names:
<typeMappings>
<uuid>com.example.MyUuid</uuid>
<date-time>java.time.Instant</date-time>
</typeMappings>
Precedence, highest first:
- per-property
x-java-typevendor extension typeMappingsentry keyed byformattypeMappingsentry keyed bytype- the built-in default type
So given the mappings above, { type: string, format: uuid } becomes
com.example.MyUuid, and a plain { type: string } keeps
String unless a string key is also configured. The import is derived
from the fully-qualified value (java.lang and unqualified names are emitted without
an import).
Choosing an override mechanism
- One property, non-standard type →
x-java-typeon that property. - One property, a
java.timetype → an extendedformatvalue (terser). - Every property of a given
format/type→typeMappings(one global entry). - Every
date-timeto a single type →dateTimeType.