ValueBinding

com.tersesystems.blindsight.jsonld.ValueBinding
final case class ValueBinding[T](key: ValueBindingKey)(implicit evidence$3: ValueMapper[T]) extends Binding

A binding between a key that is a "JSON-LD value" and a Scala type that can be represented as that value. A ValueMapper is responsible for doing the conversion.

You can define your own ValueMapper for custom types, and primitives (String, Int, etc) are already defined:

val givenName  = schemaOrg("givenName").bindValue[String]
val willPerson = NodeObject(
 givenName    -> "Person"
)

Using a "null" is done by binding to an Option[T] of the type you want:

val givenName  = schemaOrg("givenName").bindValue[Option[String]]
val willPerson = NodeObject(
 givenName  -> None
)

Some JSON-LD values are represented as "value objects", notably strings with languages and typed values.

To represent a string value:

val givenName  = schemaOrg("givenName").bindValue[String]
val willPerson = NodeObject(
 givenName -> Value("Will", StringDirection.LeftToRight, "en"),
)

You can require string values over literals by binding explicitly:

val givenName  = schemaOrg("givenName").bindValue[StringValue]

Likewise typed values are usually converted but can be defined explicitly:

val name        = schemaOrg("name").bindValue[String]
val dateCreated = schemaOrg("dateCreated").bindValue[TypedValue]
val localDate = LocalDate.of(2020, 1, 1)
val abridgedMobyDick = NodeObject(
 `@type`     -> "Book",
 name        -> "Moby Dick",
 dateCreated -> Value(DateTimeFormatter.ISO_DATE.format(localDate), xsdDate)
)

You can map any type to a value using a custom ValueMapper:

val `@type` = Keyword.`@type`.bindIRI
val schemaOrg: Vocab        = IRI("https://schema.org/").vocab
val name: ValueBinding[String] = schemaOrg("name").bindValue[String]
val value: ValueBinding[Int]   = schemaOrg("value").bindValue[Int]

implicit val currencyMapper: ValueMapper[Currency] = ValueMapper { currency =>
 Value(currency.getCurrencyCode)
}
val currency: ValueBinding[Currency] = schemaOrg("currency").bindValue[Currency]

Attributes

T

the type which has a ValueMapper type class instance

key

the value binding key

Source:
Binding.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def ->(value: T): NodeEntry

Alias for bind.

Alias for bind.

Attributes

value

the value

Returns:

the node entry

Source:
Binding.scala
def ->(value: Value[T]): NodeEntry

Binds to a value of T.

Binds to a value of T.

Attributes

value

the value

Returns:

the node entry

Source:
Binding.scala
def bind(value: T): NodeEntry

Binds to a value of T.

Binds to a value of T.

Attributes

value

the value

Returns:

the node entry

Source:
Binding.scala
def bind(value: Value[T]): NodeEntry

Binds to a value of T.

Binds to a value of T.

Attributes

value

the value

Returns:

the node entry

Source:
Binding.scala
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
Any
Source:
Binding.scala

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product