RdfLiteral.mapperInstance constructor

const RdfLiteral.mapperInstance(
  1. LiteralTermMapper instance, {
  2. MapperDirection direction = MapperDirection.both,
})

Creates a reference to a directly provided mapper instance for this literal term.

This allows you to supply a pre-existing instance of a LiteralTermMapper for this class. Useful when your mapper requires constructor parameters or complex setup that cannot be handled by simple instantiation.

This is the most direct method for providing custom serialization logic, especially when the mapper needs configuration or context from the application.

Example:

// Create a pre-configured mapper with const constructor:
const tempMapper = TemperatureMapper(
  unit: TemperatureUnit.celsius,
  precision: 2,
  locale: 'en_US',
);

@RdfLiteral.mapperInstance(tempMapper)
class Temperature {
  final double value;
  Temperature(this.value);
}

Note: Since annotations in Dart must be evaluated at compile-time, the mapper instance must be a compile-time constant.

Implementation

const RdfLiteral.mapperInstance(LiteralTermMapper instance, {super.direction})
    : toLiteralTermMethod = null,
      fromLiteralTermMethod = null,
      datatype = null,
      super.mapperInstance(instance);