RdfLiteral.namedMapper constructor

const RdfLiteral.namedMapper(
  1. String name, {
  2. MapperDirection direction = MapperDirection.both,
})

Creates a reference to a named mapper for this literal term.

Use this constructor when you want to provide a custom LiteralTermMapper implementation via dependency injection. When using this approach, you must:

  1. Implement the mapper yourself
  2. Instantiate the mapper (outside of the generated code)
  3. Provide the mapper instance as a named parameter to initRdfMapper

The name will correspond to a parameter in the generated initRdfMapper function.

This approach is particularly useful for complex value objects that require special serialization logic or context-dependent conversions.

Example:

@RdfLiteral.namedMapper('temperatureMapper')
class Temperature {
  final double celsius;
  Temperature(this.celsius);
  // ...
}

// You must implement the mapper:
class MyTemperatureMapper implements LiteralTermMapper<Temperature> {
  // Your implementation...
}

// In initialization code:
final tempMapper = MyTemperatureMapper();
final rdfMapper = initRdfMapper(temperatureMapper: tempMapper);

Implementation

const RdfLiteral.namedMapper(String name, {super.direction})
    : toLiteralTermMethod = null,
      fromLiteralTermMethod = null,
      datatype = null,
      super.namedMapper(name);