Я пытаюсь написать класс case для BSONCollection, но я не могу найти никаких операций чтения и записи в JsValue. Существуют ли BSONDocumentWriter и BSONDocumentReader для JsValue? О, какие-нибудь предложения о том, как написать один? это мой класс случая: Правило:
case class Rule(_id: BSONObjectID,
metadata: Metadata,
conditions: List[Condition])
Метаданные:
case class Metadata(
name: String,
description: String,
active: Boolean,
// Optional:
refId: Option[BSONObjectID],
keys: Option[List[Key]],
createdAt: Option[Instant],
lastVersionExists: Option[String],
data: Option[JsValue],
externalId: Option[String]
)
Условие:
case class Condition(name: String,
`type`: LogicType,
data: JsValue)
и пишет и читает:
implicit object BSONInstantHandler extends BSONHandler[BSONDateTime, Instant] {
def read(bson: BSONDateTime): Instant = Instant.ofEpochMilli(bson.value)
def write(date: Instant) = BSONDateTime(date.toEpochMilli)
}
object LogicTypeReader extends BSONReader[BSONString, LogicType] {
override def read(bson: BSONString): LogicType = LogicType.namesToValuesMap(bson.value)
}
object LogicTypeWriter extends BSONWriter[LogicType, BSONString] {
override def write(t: LogicType): BSONString = BSONString(t.entryName)
}
// Reads
implicit def LogicTypeReads: BSONReader[BSONString, LogicType] = LogicTypeReads
implicit val MetadataReader: BSONDocumentReader[Metadata] = Macros.reader[Metadata]
implicit val KeyReader: BSONDocumentReader[Key] = Macros.reader[Key]
implicit val ConditionReader: BSONDocumentReader[Condition] = Macros.reader[Condition]
implicit val RuleReader: BSONDocumentReader[Rule] = Macros.reader[Rule]
// Writes
implicit def LogicTypeWrites: BSONWriter[LogicType, BSONString] = LogicTypeWrites
implicit val MetadataWrites: BSONDocumentWriter[Metadata] = Macros.writer[Metadata]
implicit val KeyWrites: BSONDocumentWriter[Key] = Macros.writer[Key]
implicit val ConditionWrites: BSONDocumentWriter[Condition] = Macros.writer[Condition]
implicit val RuleWrites: BSONDocumentWriter[Rule] = Macros.writer[Rule]
Спасибо!
Implicit not found for '..': reactivemongo.api.bson.BSONReader[play.api.libs.json.JsValue]
, но я использую:Implicit not found for 'data': reactivemongo.bson.BSONReader[play.api.libs.json.JsValue, _]
(без .API), какие-либо предложения? Спасибо! @cchantep - person Zvi Mints   schedule 07.08.2020Condition
) - person cchantep   schedule 07.08.2020"org.reactivemongo" %% "play2-reactivemongo" % "0.18.8-play27"`` for reactive mongo and play:
com.typesafe.play % sbt-plugin % 2.7.2``` Что касается вопроса, я не могу создавать писатели и читатели для данных в классе метаданных, а также за данные в состоянии Спасибо! @cchantep - person Zvi Mints   schedule 07.08.2020