RdfProperty constructor

const RdfProperty(
  1. IriTerm? predicate, {
  2. bool include = true,
  3. dynamic defaultValue,
  4. bool includeDefaultsInSerialization = false,
  5. IriMapping? iri,
  6. LocalResourceMapping? localResource,
  7. LiteralMapping? literal,
  8. GlobalResourceMapping? globalResource,
  9. CollectionMapping? collection = const CollectionMapping.auto(),
  10. Type? itemType,
  11. ContextualMapping? contextual,
  12. 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 reference
  • localResource - Treats property as a nested anonymous resource
  • literal - Applies custom literal serialization
  • globalResource - Treats property as a resource with its own IRI
  • contextual - 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 matching Mapper<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 for rdfList, 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;