Annotation Type DtoConvert
Mark a DTO field or accessor to be populated via a custom conversion method rather than a
plain getter copy.
Used with generated entity-to-DTO graph mapping (see query.mapTo(SomeDto.class)).
Combinable with DtoPath when the source value also needs a path/rename override.
The referenced method() on value() is resolved at codegen time and
dispatched one of two ways:
- Static method - the generated mapper emits a direct static call
(
ConverterType.method(source.getX())). No registration required - intended for common, reusable, dependency-free scalar coercions (e.g.shorttoboolean, an enum to/from aString) that may apply across many unrelated entity/DTO pairs. - Instance method - the generated mapper resolves an instance of
value()viaio.ebean.DtoConverterManager.get(ConverterType.class)once (wired as a constructor parameter/field, the same shape as nested-mapper constructor injection), then callsconversions.method(source.getX()). Intended for conversions that need a real dependency (e.g. a cipher) - the instance must be registered viaDtoConverterManager.put(...)before theDatabaseis built.
public record Driver(
...
@DtoPath("encryptedDriverId")
@DtoConvert(value = DriverConversions.class, method = "decrypt")
String driverId,
...
) { }
This is purely a compile-time / codegen-time hint - the DTO itself remains a plain, framework-free type with no runtime dependency on this annotation.
-
Required Element Summary
Required Elements
-
Element Details
-
value
Class<?> valueThe type declaring the conversion method - an arbitrary app-defined shape, no ebean-mandated interface. -
method
-