RdfMapValue class

Designates a property or class as the value in a mapped Map<K,V> collection.

This annotation works with @RdfMapEntry and @RdfMapKey to enable proper serialization and deserialization of Map structures in RDF. During serialization, each map entry is fully serialized as a separate resource in the RDF graph.

The RDF mapper needs to know both the key and value of each Map entry. Since RDF has no native concept of key-value pairs, we need to explicitly mark which properties or classes represent the key and value components in the RDF representation.

There are two valid ways to use the RDF Map annotations to model a Map<K,V>:

  1. Property-level annotations - one property as key, one property as value:
@RdfLocalResource()
class CounterEntry {
  @RdfProperty(ExampleVocab.key)
  @RdfMapKey() // Marks this property as the key
  final String key;

  @RdfProperty(ExampleVocab.count)
  @RdfMapValue() // Marks this property as the value
  final int count;

  CounterEntry(this.key, this.count);
}

@RdfLocalResource()
class Counters {
  @RdfProperty(ExampleVocab.counters)
  @RdfMapEntry(CounterEntry)
  final Map<String, int> counts; // Keys and values are extracted from CounterEntry

  Counters(this.counts);
}

In this approach, both the key and value are individual properties that are specifically marked. The Map's generic type parameters must match the types of these properties (e.g., Map<String, int>). There must not be any additional properties in the CounterEntry class except for computed/derived ones. Key and Value properties must be sufficient for full serialization.

  1. Class-level annotation - entire entry class represents the value:
// The class with @RdfMapValue at class level
@RdfMapValue() // Class-level annotation - the whole class represents a value
@RdfLocalResource()
class SettingsEntry {
  // When @RdfMapValue is used at class level, @RdfMapKey can be on a derived property
  // that doesn't need to be an RDF property itself. It is perfectly fine
  // to use it on an @RdfProperty, though.
  @RdfMapKey() // The key property - can be computed/derived
  String get key => id; // This is a derived property used as a map key

  // The actual RDF property that stores the identifier
  @RdfProperty(ExampleVocab.settingId)
  final String id;

  // Multiple RDF properties can be part of the value
  @RdfProperty(ExampleVocab.settingPriority)
  final int priority;

  @RdfProperty(ExampleVocab.settingEnabled)
  final bool enabled;

  @RdfProperty(ExampleVocab.settingDescription)
  final String description;

  // No @RdfMapValue needed on any property since the class itself
  // is annotated with @RdfMapValue
  SettingsEntry(this.id, this.priority, this.enabled, this.description);
}

// In your Resource class:
@RdfLocalResource()
class Settings {
  @RdfProperty(ExampleVocab.settings)
  @RdfMapEntry(SettingsEntry) // Using the class with class-level @RdfMapValue
  Map<String, SettingsEntry> allSettings; // Key is String, value is the whole SettingsEntry

  Settings(this.allSettings);
}

This second approach is particularly useful when the value needs to be a complex object with multiple properties. The entire object becomes the value in the Map, with one of its properties designated as the key. When using class-level @RdfMapValue, the property marked with @RdfMapKey can be a derived Dart property (getter) that doesn't necessarily map to an RDF property itself.

You can have as many @RdfProperty properties in the class with this approach as you want, but all other properties must be computed/derived properties that don't need serialization.

Inheritance

Constructors

RdfMapValue()
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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