RdfIri.mapper constructor

const RdfIri.mapper(
  1. Type mapperType, {
  2. 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 IRI mapping for this class. The type must implement IriTermMapper.

This approach is useful when the mapper has a default constructor and doesn't require additional configuration parameters.

Example:

@RdfIri.mapper(StandardIsbnMapper)
class ISBN {
  final String value;
  ISBN(this.value);
}

// The mapper implementation must be accessible to the generator:
class StandardIsbnMapper implements IriTermMapper<ISBN> {
  @override
  IriTerm toRdfTerm(ISBN isbn, SerializationContext context) {
    return context.createIriTerm('urn:isbn:${isbn.value}');
  }

  @override
  ISBN fromRdfTerm(IriTerm term, DeserializationContext context) {
    final iri = term.value;
    if (!iri.startsWith('urn:isbn:')) {
      throw ArgumentError('Invalid ISBN IRI: $iri');
    }
    return ISBN(iri.substring(9));
  }
}

Implementation

const RdfIri.mapper(Type mapperType, {super.direction})
    : template = null,
      fragmentTemplate = null,
      super.mapper(mapperType);