RdfLocalResource.namedMapper constructor

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

Creates a reference to a named mapper for this local resource.

Use this constructor when you want to provide a custom LocalResourceMapper 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.

Example:

class Book {
  // Using a custom mapper for a nested Chapter object
  @RdfProperty(
    SchemaBook.chapter,
    localResource: LocalResourceMapping.namedMapper('customChapterMapper')
  )
  final Chapter chapter;
}

// You must implement the mapper:
class MyChapterMapper implements LocalResourceMapper<Chapter> {
  // Your implementation...
}

// In initialization code:
final chapterMapper = MyChapterMapper();
final rdfMapper = initRdfMapper(customChapterMapper: chapterMapper);

Implementation

const RdfLocalResource.namedMapper(String name, {super.direction})
    : classIri = null,
      super.namedMapper(name);