ContextualMapping class
Configuration for contextual property mapping.
Contextual mapping allows a property's serializer and deserializer to access the parent object, parent subject, and full context during RDF serialization and deserialization operations.
This enables complex scenarios where property mapping depends on:
- Parent object state and other properties
- Parent resource's IRI or blank node identifier
- Full serialization/deserialization context
Common use cases include:
- Computing dependent object IRIs based on parent properties
- Creating nested resources that reference their container
- Context-dependent mapping strategies
- Cross-property validation during deserialization
Usage
Use contextual mapping by specifying it in the @RdfProperty annotation:
class Document<T> {
@RdfProperty(FoafDocument.primaryTopic)
final String documentIri;
@RdfProperty(
FoafDocument.primaryTopic,
contextual: ContextualMapping.namedProvider("primaryTopic")
)
final T primaryTopic;
}
This generates a mapper constructor that requires a SerializationProvider:
final mapper = DocumentMapper<Person>(
primaryTopic:
SerializationProvider.iriContextual((IriTerm iri) =>
PersonMapper(documentIriProvider: () => iri.value)),
);
Generated Code Contract
When using ContextualMapping.namedProvider("example"), the generator creates:
Constructor Parameter:
final SerializationProvider<ParentType, T> example;
Generated Mapper Constructor:
const DocumentMapper({
required SerializationProvider<Document<T>, T>
primaryTopic,
}) : _primaryTopicSerializationProvider = primaryTopic;
Usage During Serialization:
serializer: _primaryTopicSerializationProvider.serializer(
resource, // The parent object being serialized
subject, // The parent's IRI or blank node
context, // Full serialization context
)
Usage During Deserialization:
deserializer: _primaryTopicSerializationProvider.deserializer(
subject, // The parent's IRI or blank node
context, // Full deserialization context
)
The SerializationProvider encapsulates both serializer and deserializer creation based on the parent context, providing a more cohesive API.
- Inheritance
-
- Object
- BaseMapping<
SerializationProvider> - ContextualMapping
Constructors
- ContextualMapping.namedProvider(String mapperName)
-
Creates a named contextual mapping configuration.
const
- ContextualMapping.provider(Type type)
-
const
- ContextualMapping.providerInstance(SerializationProvider instance)
-
const
Properties
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