IriMapping class

Configures mapping details for IRI terms in RDF at the property level.

This class is used within the @RdfProperty annotation to customize how objects are serialized as IRI terms in RDF. Unlike class-level mappings configured with @RdfIri, these mappings are scoped to the specific property where they are defined and are not registered globally.

In RDF, IRIs (Internationalized Resource Identifiers) are used to uniquely identify resources and properties. This mapping is ideal for:

  • Properties representing identifiers that need custom formatting as IRIs
  • References to other resources with specific IRI patterns
  • Properties that must be serialized as IRIs rather than literals
  • Customizing resource references for specific relationship contexts

Important: Mappers configured through IriMapping are only used by the specific ResourceMapper whose property annotation references them. They are not registered in the global mapper registry and won't be available for use by other mappers or for direct lookup.

Property Type Support

The default constructor (IriMapping([template])) only supports String properties. For non-String types like value objects (e.g., UserId or ISBN classes), you have two options:

  1. Use one of the mapper constructors:

    • .namedMapper() - Reference a named mapper provided at runtime
    • .mapper() - Instantiate a mapper from a type
    • .mapperInstance() - Use a pre-configured mapper instance
  2. Annotate the class of the property value with @RdfIri and implement the template logic based on fields of that class there. This approach leverages automatic mapper registration and is often cleaner when the value class is fully under your control.

These approaches ensure proper serialization and deserialization for complex types.

Examples

For String properties:

@RdfProperty(
  Dcterms.creator,
  iri: IriMapping('https://example.org/users/{userId}')
)
final String userId;

For value objects:

@RdfProperty(
  SchemaPerson.identifier,
  iri: IriMapping.mapper(UserIdMapper)
)
final UserId userId;

Without this override, the property would use the default mapper registered for the value class, which might be configured with @RdfIri at the class level. The key difference is that the class-level mapper is globally registered (unless registerGlobally: false is specified), while this property-level mapping is only used for this specific property.

Enum Property Mapping

Can be used to override enum IRI serialization at the property level:

@RdfGlobalResource(...)
class Product {
  // Uses the enum's default @RdfIri mapping with @RdfEnumValue annotations
  @RdfProperty(ProductSchema.condition)
  final ItemCondition condition;

  // Override the enum's default mapping with a custom mapper for this property
  @RdfProperty(
    ProductSchema.format,
    iri: IriMapping.namedMapper('customFormatMapper')
  )
  final BookFormat format;

  // Use a different IRI template for the same enum in this specific context
  @RdfProperty(
    ProductSchema.category,
    iri: IriMapping('http://local.vocab/{value}/category')
  )
  final ItemCondition categoryCondition; // Same enum, different IRI pattern
}

This is particularly useful when you need different IRI patterns for the same enum type in different contexts, or when you want to override the global enum mapping for specific properties.

Inheritance

Constructors

IriMapping([String? template])
Creates an IRI mapping template for property-specific IRI generation.
const
IriMapping.mapper(Type mapperType)
Creates a reference to a mapper that will be instantiated from the given type.
const
IriMapping.mapperInstance(IriTermMapper instance)
Creates a reference to a directly provided mapper instance for this IRI term.
const
IriMapping.namedFactory(String name, [Object? configInstance])
Creates a reference to a named factory function for creating IRI mappers.
const
IriMapping.namedMapper(String name)
Creates a reference to a named mapper for this IRI term.
const
IriMapping.withFragment(String baseIriTemplate, String fragmentTemplate)
Creates a mapping for generating IRIs by appending a fragment to a base IRI.
const

Properties

fragmentTemplate String?
Optional template for the fragment identifier to append to the base IRI.
final
hashCode int
The hash code for this object.
no setterinherited
mapper MapperRef<IriTermMapper>?
Provides a MapperRef if a custom mapper is specified.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
template String?
An optional template string for constructing the IRI.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited