CollectionMapping.mapperInstance constructor

const CollectionMapping.mapperInstance(
  1. Mapper instance
)

Creates a reference to a directly provided collection mapper instance.

This allows you to supply a pre-existing instance of a collection mapper. Useful when your mapper requires constructor parameters or complex setup that cannot be handled by simple instantiation.

The mapper will only be used for the specific property annotated with this mapping.

Example:

// Create a pre-configured collection mapper with const constructor -
// note that the mapper instance must be a compile-time constant and that
// it must be a Mapper<List<Track>> in our example here due to the field type:
const orderedTrackListMapper = CustomOrderedTrackListMapper(
  preserveOrder: true,
  validateUniqueness: false,
);

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

Note: Since annotations in Dart must be evaluated at compile-time, the mapper instance must be a compile-time constant.

Implementation

const CollectionMapping.mapperInstance(Mapper instance)
    : isAuto = false,
      factory = null,
      super.mapperInstance(instance);