contextual property
Optional contextual mapping configuration.
When provided, the generated mapper will require a SerializationProvider that has access to the parent object, parent subject, and full context during RDF operations.
This enables complex mapping scenarios where the property's serialization or deserialization depends on:
- The parent object's state and other properties
- The parent resource's IRI (for global resources) or blank node (for local resources)
- The full serialization/deserialization context
Usage:
class Document<T> {
@RdfProperty(FoafDocument.primaryTopic)
final String documentIri;
@RdfProperty(
FoafDocument.primaryTopic,
contextual: ContextualMapping.namedProvider("primaryTopic")
)
final T primaryTopic;
}
Generated Code: The mapper constructor will require a SerializationProvider:
DocumentMapper<T>({
required SerializationProvider<Document<T>, T> primaryTopic,
});
Consumer Implementation:
final mapper = DocumentMapper<Person>(
primaryTopic: SerializationProvider.iriContextual((IriTerm iri) =>
PersonMapper(documentIriProvider: () => iri.value)),
);
The SerializationProvider encapsulates both serializer and deserializer creation based on the parent context, providing a more cohesive API.
Compatibility: Cannot be used together with iri/literal/globalResource/localResource parameters as contextual mapping provides its own serialization strategy.
Implementation
final ContextualMapping? contextual;