CollectionMapping.namedMapper constructor

const CollectionMapping.namedMapper(
  1. String name
)

Creates a reference to a named collection mapper that will be injected at runtime.

Use this constructor when you want to provide your own custom collection mapper implementation. The mapper you provide will determine how the collection is serialized to and deserialized from RDF. When using this approach, you must:

  1. Implement a collection mapper (e.g., Mapper<List<T>>)
  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 mapper will only be used for the specific property annotated with this mapping.

Example:

class Playlist {
  @RdfProperty(
    PlaylistVocab.tracks,
    collection: CollectionMapping.namedMapper('orderedTrackMapper')
  )
  final List<Track> tracks;
}

// You must implement the collection mapper:
class OrderedTrackMapper implements UnifiedResourceMapper<List<Track>> {
  final Serializer<Track> trackSerializer;
  final Deserializer<Track> trackDeserializer;

  OrderedTrackMapper({
    required this.trackSerializer,
    required this.trackDeserializer,
  });

  // Implementation details...
}

// In initialization code:
final trackMapper = OrderedTrackMapper(/* params */);
final rdfMapper = initRdfMapper(orderedTrackMapper: trackMapper);

Implementation

const CollectionMapping.namedMapper(String name)
    : isAuto = false,
      factory = null,
      super.namedMapper(name);