NodeObjectBinding
com.tersesystems.blindsight.jsonld.NodeObjectBinding
final case class NodeObjectBinding[T](key: BindingKey)(implicit evidence$5: NodeObjectMapper[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 NodeObjectMapper is responsible for doing the conversion.
Most of the time you'll use a custom NodeObjectMapper to convert appropriately, building on
other bindings in your context. For example, to render a MonetaryAmount
class as a node
object, you can add the binding in a context that contains currency
and value
bindings:
case class MonetaryAmount(currency: Currency, value: Int)
/** Represent as https://schema.org/MonetaryAmount instance */
trait MonetaryAmountMapper extends MyContext {
implicit val monetaryAmountMapper: NodeObjectMapper[MonetaryAmount] = NodeObjectMapper { ma =>
NodeObject(
`@type` -> monetaryAmountType,
currency -> ma.currency,
value -> ma.value
)
}
}
object MonetaryAmountMapper extends MonetaryAmountMapper
And then you can use bindObject[MonetaryAmount]
.
import MonetaryAmountMapper._
val estimatedSalary: NodeObjectBinding[MonetaryAmount] =
schemaOrg("estimatedSalary").bindObject[MonetaryAmount]
You can also bind a simple NodeObject without mapping. For example, you can represent an organization with an employee as a raw NodeObject:
val employee = schemaOrg("employee").bindObject[NodeObject]
val organization = NodeObject(
`@type` -> schemaOrg("Organization")
name -> "Terse Systems",
employee -> NodeObject(
`@type` -> schemaOrg("Person")
givenName -> "Will",
)
)
Attributes
- Source:
- Binding.scala
- Graph
- Supertypes