Annotation Type DtoMapping
query.mapTo(SomeDto.class)).
Declared on a neutral holder - typically a package-info.java - rather than on the DTO
or the entity itself. This matters because:
- The DTO type is often owned/generated elsewhere (e.g. from an OpenAPI spec) and shouldn't need to know about, or be annotated with, an internal persistence/entity type.
- One entity may be the source for several different DTOs (e.g. a summary vs. a detail view), and one entity/DTO pair may need re-registering from multiple consuming modules.
@DtoMapping(source = Customer.class, target = CustomerDto.class)
@DtoMapping(source = Contact.class, target = ContactDto.class)
package org.example.dto;
Purely a compile-time / codegen-time trigger - never needed at runtime, so this annotation itself carries no runtime footprint (source retention).
-
Nested Class Summary
Nested Classes -
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionControls whether the generated mapper constructs the target DTO via a positional constructor call or via a detected builder (a staticTarget.builder()factory returning a type with fluent per-property setters and abuild()method - the shapeavaje-recordbuilder's@RecordBuildergenerates).String[]NestedToOne/ToManyDTO property names (declared field names on the target, not source paths), or non-primitive scalar property names (e.g. a@DtoConvert-backedListproperty with no registered nested DTO mapping of its own), to exclude from this named variant - only meaningful whenname()is non-empty.Override the simple class name of the generated mapper.Override the package the generated mapper is written to.Name this mapping as a named variant of an already-registered(source, target)pair, rather than the primary/base mapping.Controls whether the generated mapper constructs the target DTO via a detected setter-based (mutable JavaBean) construction path - a public no-arg constructor plus asetXxx(propertyType)setter for every mapped property, the shape JAXB/XSD-generated legacy SOAP types commonly follow - rather than a positional constructor call or a builder chain.
-
Element Details
-
source
Class<?> sourceThe source entity (or embeddable) type to map from. -
target
Class<?> targetThe target DTO type to map to. -
mapperPackage
String mapperPackageOverride the package the generated mapper is written to.Defaults to the target DTO's own package - unless the source and/or target type belongs to a different module than the one being processed, in which case the generated mapper is placed in a package derived from the processing module's own name instead, to avoid a Java module "split package" violation (the same fallback
avaje-jsonbuses for@Json.Importof external types).- Default:
""
-
mapperName
String mapperNameOverride the simple class name of the generated mapper.Defaults to the target DTO's own simple name suffixed with
Mapper(e.g. a mapping targetingFleetgeneratesFleetMapper). Set this when that default name would clash with an existing hand-written class of the same name (e.g. a legacy mapper still in use elsewhere that can't be renamed/removed yet) - the generated mapper can then be given a distinct name (and, if needed, paired withmapperPackage()too) so both classes can coexist.- Default:
""
-
name
String nameName this mapping as a named variant of an already-registered(source, target)pair, rather than the primary/base mapping.The same
(source, target)pair may be declared more than once - one base declaration (leavingname()empty) plus any number of named variants - all generated into a single shared mapper class (one class per target, not one per variant). Each variant excludes one or more nestedToOne/ToManyDTO properties (seeexclude()) from both its ownfetchGroupand its mapped output, letting the same target DTO type be populated in more than one shape (e.g. with vs. without an expensive nested collection) without generating a second target type.The generated mapper exposes each variant as a same-named method returning its own
DtoMapper<SOURCE, TARGET>view, e.g.name = "noFleets"generates anoFleets()accessor method - pass its result toquery.mapTo(Target.class, mapper.noFleets()).- Default:
""
-
exclude
String[] excludeNestedToOne/ToManyDTO property names (declared field names on the target, not source paths), or non-primitive scalar property names (e.g. a@DtoConvert-backedListproperty with no registered nested DTO mapping of its own), to exclude from this named variant - only meaningful whenname()is non-empty. Excluded properties are omitted from this variant'sfetchGroup(no fetch/join/select is issued for them) and mapped tonull(a single-valued property) or an empty list (aList-typed property) in this variant's output, rather than being populated from the source graph.A primitive-typed scalar property cannot be excluded - there's no type-safe "absent" value for it.
- Default:
{}
-
builder
DtoMapping.Builder builderControls whether the generated mapper constructs the target DTO via a positional constructor call or via a detected builder (a staticTarget.builder()factory returning a type with fluent per-property setters and abuild()method - the shapeavaje-recordbuilder's@RecordBuildergenerates).- Default:
AUTO
-
setter
DtoMapping.Setter setterControls whether the generated mapper constructs the target DTO via a detected setter-based (mutable JavaBean) construction path - a public no-arg constructor plus asetXxx(propertyType)setter for every mapped property, the shape JAXB/XSD-generated legacy SOAP types commonly follow - rather than a positional constructor call or a builder chain. A matching setter may either returnvoidor return the target type itself (fluent-style, e.g.public Target setXxx(...) { ...; return this; }) - either way the generated code calls it as a plain statement and ignores any return value.- Default:
AUTO
-