LiteralMapping.mapperInstance constructor
const
LiteralMapping.mapperInstance(
- LiteralTermMapper instance
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.
It will only be used for the Resource Mapper whose property is annotated with this mapping, not automatically be registered globally.
This approach is particularly useful 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',
);
@RdfGlobalResource(...)
class WeatherStation {
// Using a custom pre-configured mapper for a Temperature object
@RdfProperty(
WeatherSchema.temperature,
literal: LiteralMapping.mapperInstance(tempMapper)
)
final Temperature temperature;
}
Note: Since annotations in Dart must be evaluated at compile-time, the mapper instance must be a compile-time constant.
Implementation
const LiteralMapping.mapperInstance(LiteralTermMapper instance)
: language = null,
datatype = null,
super.mapperInstance(instance);