template property

String? template
final

An optional template string for constructing the IRI.

Template variables are enclosed in curly braces and can be of two types:

  1. 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
  2. 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 to initRdfMapper.
    • 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 IriStrategy specifies providedAs parameter. 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

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:

  1. Use one of the mapper constructors (.namedMapper(), .mapper(), or .mapperInstance()) to provide explicit conversion logic, or
  2. Annotate the value class itself with @RdfIri and implement the template logic there.

Implementation

final String? template;