ParameterConverter

interface ParameterConverter<T : Any>

Turns a Kotlin value into something a codec can encode for the wire.

This is the write half of the conversion SPI, and the mirror of ResultConverter. A converter does not produce bytes: it produces a value some registered codec knows how to encode — a String for an enum label, a PgComposite for a data class — and the codec does the rest. Register one on a session through TypeManager.registerParameterConverter, or on a single query through registerParameterConverter.

Converters are consulted in reverse registration order, so a later one wins over an earlier one, and the first whose canConvert answers true takes the value. A value nothing claims is passed through untouched, which is right for a scalar the codec already accepts; where the target OID is known and its codec cannot accept that class, the driver raises MappingException (NO_CONVERTER_FOUND) naming both sides instead of letting it fail one layer down as an encoding error.

Type Parameters

T

The Kotlin type this converter accepts.

Inheritors

Properties

Link copied to clipboard
abstract val supportedClass: KClass<T>

The Kotlin class this converter handles. The default canConvert also accepts its subtypes.

Functions

Link copied to clipboard
open fun canConvert(sourceClass: KClass<*>, expectedOid: Int, context: SerializationContext): Boolean

Decides whether this converter handles the value at hand.

Link copied to clipboard
abstract fun convert(source: T, expectedOid: Int, context: SerializationContext): Any

Converts a value this converter has claimed into something a codec can encode.

Link copied to clipboard
open fun getDefaultTypeName(sourceClass: KClass<*>, context: SerializationContext): QualifiedName?

Names the PostgreSQL type to declare for the converted value, where nothing else has named one.