RdfGlobalResource.namedMapper constructor

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

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

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

The direction parameter controls whether the mapper handles serialization, deserialization, or both. Defaults to MapperDirection.both.

This approach is particularly useful for resources that require complex mapping logic or external context (like base URLs) that might vary between deployments.

Note: The mapper will be registered globally in the RdfMapper instance. If you need non-global registration, simply do not annotate the class with @RdfGlobalResource.

Example:

// Bidirectional mapper (default)
@RdfGlobalResource.namedMapper('customBookMapper')
class Book {
  // ...
}

// Deserialize-only mapper
@RdfGlobalResource.namedMapper(
  'customBookMapper',
  direction: MapperDirection.deserializeOnly
)
class Book {
  // ...
}

// You must implement the mapper:
class MyBookMapper implements GlobalResourceMapper<Book> {
  // Your implementation...
}

// In initialization code:
final bookMapper = MyBookMapper();
final rdfMapper = initRdfMapper(customBookMapper: bookMapper);

Implementation

const RdfGlobalResource.namedMapper(String name,
    {MapperDirection direction = MapperDirection.both})
    : iri = null,
      classIri = null,
      vocab = null,
      subClassOf = null,
      metadata = null,
      label = null,
      comment = null,
      fragment = null,
      super.namedMapper(name, direction: direction);