RdfLiteral.mapper constructor
const
RdfLiteral.mapper(
- Type mapperType, {
- MapperDirection direction = MapperDirection.both,
Creates a reference to a mapper that will be instantiated from the given type.
The generator will create an instance of mapperType to handle literal
term mapping for this class. The type must implement LiteralTermMapper<T>
where T is the annotated class and it must have a no-argument default constructor.
This approach is useful when the mapper has a default constructor and doesn't require additional configuration parameters.
Example:
@RdfLiteral.mapper(TemperatureMapper)
class Temperature {
final double celsius;
Temperature(this.celsius);
// ...
}
// The mapper implementation must be accessible to the generator:
class TemperatureMapper implements LiteralTermMapper<Temperature> {
@override
LiteralTerm toRdfTerm(Temperature temp, SerializationContext context) {
return LiteralTerm('${temp.celsius}°C');
}
@override
Temperature fromRdfTerm(LiteralTerm term, DeserializationContext context) {
return Temperature(double.parse(term.value.replaceAll('°C', '')));
}
}
Implementation
const RdfLiteral.mapper(Type mapperType, {super.direction})
: toLiteralTermMethod = null,
fromLiteralTermMethod = null,
datatype = null,
super.mapper(mapperType);