RdfProperty constructor
- IriTerm? predicate, {
- bool include = true,
- dynamic defaultValue,
- bool includeDefaultsInSerialization = false,
- IriMapping? iri,
- LocalResourceMapping? localResource,
- LiteralMapping? literal,
- GlobalResourceMapping? globalResource,
- CollectionMapping? collection = const CollectionMapping.auto(),
- Type? itemType,
- ContextualMapping? contextual,
- bool noDomain = false,
Creates an RDF property mapping annotation.
predicate - The RDF predicate IRI that identifies this property in the graph,
typically from a vocabulary constant (e.g., SchemaBook.name, Dcterms.creator).
include - Controls serialization behavior. When false, creates a one-way mapping
where the property is read from RDF during deserialization but not written back
during serialization. Useful for properties managed internally after loading.
defaultValue - Fallback value for properties missing during deserialization.
Critical for non-nullable properties. Without a default, non-nullable properties
will throw an error if missing from RDF data.
includeDefaultsInSerialization - When true, includes properties even if they
match their default value. When false (default), omits them for more compact RDF.
Advanced mapping parameters (specify at most one):
iri- Treats property value as an IRI referencelocalResource- Treats property as a nested anonymous resourceliteral- Applies custom literal serializationglobalResource- Treats property as a resource with its own IRIcontextual- Enables contextual property mapping where serializers and deserializers have access to the parent object, parent subject, and full context
Most properties work with automatic type-based mapping without these advanced parameters. Only use them to override default behavior for specific cases.
collection - Specifies a custom collection mapper Type for handling collections.
When provided, the Type must implement Mapper<C> and have a constructor that matches
the Mapper<C> Function({Deserializer<T>? itemDeserializer, Serializer<T>? itemSerializer}) signature where T is the item type and C the collection type (e.g. List<T>).
If not specified, standard collections
use their respective default mappers: List<T> → UnorderedItemsListMapper,
Set<T> → UnorderedItemsSetMapper, Iterable<T> → UnorderedItemsMapper.
Well-known collection mappers include:
- Default mappers (multiple triples):
unorderedItems,unorderedItemsList,unorderedItemsSet - RDF structures (single collection):
rdfList,rdfSeq,rdfBag,rdfAlt - Custom mappers: Implement
Mapper<C>with constructor matchingMapper<C> Function({Deserializer<T>? itemDeserializer, Serializer<T>? itemSerializer})signature and refer to that type with(MyMapper) - you can of course also store the result of that call in a global const variable to have a shortcut, like we do forrdfList,rdfSeq` etc.
itemType - Explicitly specifies the item type for collection mapping when
it cannot be automatically extracted from the field's generic type parameters.
Only needed for custom collection types or complex generics.
Implementation
const RdfProperty(
this.predicate, {
this.include = true,
this.defaultValue,
this.includeDefaultsInSerialization = false,
this.iri,
this.localResource,
this.literal,
this.globalResource,
this.collection = const CollectionMapping.auto(),
this.itemType,
this.contextual,
this.noDomain = false,
}) : fragment = null,
metadata = null,
label = null,
comment = null;