LiteralMapping.namedMapper constructor

const LiteralMapping.namedMapper(
  1. String name
)

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, but the mapper will not be registered globally in the RdfMapper instance but only used for the Resource Mapper whose property is annotated with this mapping.

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

Example:

@RdfGlobalResource(...)
class WeatherStation {
  // Using a custom mapper for a Temperature object
  @RdfProperty(
    WeatherSchema.temperature,
    literal: LiteralMapping.namedMapper('temperatureMapper')
  )
  final Temperature temperature;
}

// 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 LiteralMapping.namedMapper(String name)
    : language = null,
      datatype = null,
      super.namedMapper(name);