Annotation Type DtoConvert


@Target({FIELD,METHOD}) @Retention(CLASS) public @interface 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. short to boolean, an enum to/from a String) that may apply across many unrelated entity/DTO pairs.
  • Instance method - the generated mapper resolves an instance of value() via io.ebean.DtoConverterManager.get(ConverterType.class) once (wired as a constructor parameter/field, the same shape as nested-mapper constructor injection), then calls conversions.method(source.getX()). Intended for conversions that need a real dependency (e.g. a cipher) - the instance must be registered via DtoConverterManager.put(...) before the Database is 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
    Modifier and Type
    Required Element
    Description
    The name of the conversion method on value() to invoke, taking the source property value and returning the converted DTO property value.
    The type declaring the conversion method - an arbitrary app-defined shape, no ebean-mandated interface.
  • Element Details

    • value

      Class<?> value
      The type declaring the conversion method - an arbitrary app-defined shape, no ebean-mandated interface.
    • method

      String method
      The name of the conversion method on value() to invoke, taking the source property value and returning the converted DTO property value.