RdfIri constructor
- String? template,
- bool registerGlobally = true,
- MapperDirection direction = MapperDirection.both
Creates an annotation for a class or enum to be mapped to an IRI term.
This standard constructor creates a mapper that automatically handles the
conversion between your Dart type and an IRI term. By default, this mapper is
registered within initRdfMapper when registerGlobally is true.
Template System
The template parameter supports a powerful placeholder system that works for
both classes and enums:
Placeholder Types:
{propertyName}- Values from@RdfIriPartannotated properties (percent-encoded){contextVariable}- Context variables from providers (percent-encoded){+contextVariable}- Reserved expansion for URI structure preservation
Context Variable Resolution:
Context variables are resolved from:
- Global providers in
initRdfMapper()(e.g.,baseUriProvider: () => 'https://api.example.com') - Class properties annotated with
@RdfProvides('variableName') - Parent resource's IRI, when the parent's
IriStrategyspecifiesprovidedAsparameter
Usage for Classes:
// Template with property placeholders
@RdfIri('urn:isbn:{value}')
class ISBN {
@RdfIriPart()
final String value;
ISBN(this.value);
}
// Template with context variables
@RdfIri('{+baseUri}/users/{userId}')
class UserProfile {
@RdfIriPart('userId')
final String id;
UserProfile(this.id);
}
// Direct value (no template)
@RdfIri()
class AbsoluteUri {
@RdfIriPart()
final String uri;
AbsoluteUri(this.uri);
}
Usage for Enums:
For enums, the template system provides an automatic {value} placeholder
in addition to context variables:
// Using enum value with custom @RdfEnumValue annotations
@RdfIri('https://vocab.example.com/status#{value}')
enum TaskStatus {
pending,
@RdfEnumValue('in-progress')
inProgress, // → <https://vocab.example.com/status#in-progress>
completed // → <https://vocab.example.com/status#completed>
}
// Using context variables with enums
@RdfIri('{+vocabBase}/priority/{value}')
enum Priority { low, medium, high }
For enums:
{value}resolves to the custom value from@RdfEnumValueor the enum constant name if not specified- Context variables work the same as with classes
- If no template is provided, the enum value (respecting
@RdfEnumValue) is used as the complete IRI
Parameters
template - Optional IRI template with placeholders. If not provided:
- For classes: the single
@RdfIriPartproperty value is used directly as the IRI - For enums: the enum value (respecting
@RdfEnumValueannotations) is used directly as the IRI
registerGlobally - Whether to register the generated mapper in initRdfMapper.
Set to false if the mapper should be registered manually or used at the property level instead.
Implementation
const RdfIri(
[this.template,
bool registerGlobally = true,
MapperDirection direction = MapperDirection.both])
: fragmentTemplate = null,
super(registerGlobally: registerGlobally, direction: direction);