literal property

LiteralMapping? literal
final

Specifies custom literal conversion for the property value.

Use this parameter when a property requires specialized literal serialization different from the standard mapping behavior, such as custom formatting, language tags, or datatype handling.

Only needed when there is no LiteralMapper already registered globally for the property value's type, or when you need to override the standard literal conversion for this specific property.

This provides property-specific literal conversion rules, useful when:

  • Different serialization rules are needed for the same type in different contexts
  • A property requires special datatype handling or language tags
  • You need specialized formatting for a specific property

Available LiteralMapping constructor variants:

  • .namedMapper() - reference a mapper provided to initRdfMapper
  • .mapper() - use a mapper type that will be instantiated
  • .mapperInstance() - use a specific mapper instance
  • .withLanguage() - add a language tag to string literals (e.g., "text"@en)
  • .withType() - specify a custom RDF datatype for the literal

Examples:

// Using a custom literal mapper for a property
@RdfProperty(
  SchemaBook.price,
  literal: LiteralMapping.namedMapper('currencyMapper')
)
final Price price; // Serialized using the custom 'currencyMapper'

// Adding a language tag to a string property
@RdfProperty(
  SchemaBook.description,
  literal: LiteralMapping.withLanguage('en')
)
final String description; // Serialized as "description"@en

// Specifying a custom datatype
@RdfProperty(
  SchemaBook.publicationDate,
  literal: LiteralMapping.withType(Xsd.date)
)
final String date; // Serialized with a specific datatype

Implementation

final LiteralMapping? literal;