MapTypeConverter

abstract class MapTypeConverter<S : Any, T : Any>(val sourceType: KClass<S>, val targetType: KClass<T>)

Bidirectional type converter between a source type S and a target type T.

Built-in and user converters share this exact base — same discovery, same calling convention, same way of declaring an intentionally-unsupported direction (full parity).

Override the direction(s) you support; a non-overridden direction throws MappingException.UnsupportedConversion as a runtime safety net (generated code never calls a direction the processor knows is unsupported). Declare an intentionally unsupported direction with an UnsupportedDirection-annotated = unsupported() stub.

The OrNull variants exist for sanctioned null: override one to declare "this input has no legitimate counterpart" (e.g. blank string carries no Int). A sanctioned null is silent (legitimate flow, not a degradation) and survives onFail = Throw; the total method stays total and keeps throwing for the same input.

Inheritors

Constructors

Link copied to clipboard
constructor(sourceType: KClass<S>, targetType: KClass<T>)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open fun convertFrom(target: T): S

Total reverse conversion (T -> S). Override if the direction is supported; the non-overridden default throws with a direction-precise T -> S message.

Link copied to clipboard
open fun convertFromOrNull(target: T): S?

Sanctioned-null reverse variant — override to declare inputs with no legitimate counterpart. The default delegates to convertFrom, so plain converters need not override it.

Link copied to clipboard
open fun convertTo(source: S): T

Total forward conversion (S -> T). Override if the direction is supported; the non-overridden default throws with a direction-precise S -> T message.

Link copied to clipboard
open fun convertToOrNull(source: S): T?

Sanctioned-null forward variant — override to declare inputs with no legitimate counterpart. The default delegates to convertTo, so plain converters need not override it.