template property
An optional template string for constructing the IRI.
Template variables are enclosed in curly braces and can be of two types:
-
Property variables: Correspond to values from the property this mapping is applied to
- Example: In
IriMapping('urn:isbn:{userId}'), the{userId}variable will be replaced with the value of the property it's applied to - The actual property name is used as the placeholder, creating a clear connection between the template and the property
- Example: In
-
Context variables: Variables like
{+baseUri}or{+storageRoot}that are provided through one of three methods:- Via global provider functions in
initRdfMapper(e.g.,baseUriProvider: () => 'https://example.com'). The generator will automatically add a required parameter toinitRdfMapper. - Via other properties in the same class annotated with
@RdfProvides('baseUri'). This is preferred for context variables that are already available in the class. - Via the parent resource's IRI, when the parent's
IriStrategyspecifiesprovidedAsparameter. This is useful for hierarchical structures where children need the parent's IRI. - Example:
IriMapping('{+baseUri}/users/{userId}') - The
+prefix (e.g.,{+baseUri}) indicates variables that may contain URI-reserved characters like slashes, which should not be percent-encoded when substituted
- Via global provider functions in
If no template is provided (template == null), the property value will be used directly
as the complete IRI, which is useful for properties that already contain fully qualified URIs.
Note: When using the default constructor with a template, the property must be of type
String. For non-String types like value objects (e.g., UserId), either:
- Use one of the mapper constructors (
.namedMapper(),.mapper(), or.mapperInstance()) to provide explicit conversion logic, or - Annotate the value class itself with
@RdfIriand implement the template logic there.
Implementation
final String? template;