【问题标题】:Custom meta-mapping for spray JsValue喷雾 JsValue 的自定义元映射
【发布时间】:2021-08-20 10:53:00
【问题描述】:

我需要为 spray.json.JsValue(实际上是我的模型类中的 Option[JsValue])创建一个元数据,以便将其插入到带有 JSON 字段的表中。 我尝试关注关于自定义映射/JSON 映射的 doobie 文档,所以我有这个:

  implicit val jsonMeta: Meta[JsValue] =
Meta.Advanced.other[PGobject]("json").timap[Json](
  a => parse(a.getValue).leftMap[Json](e => throw e).merge)(
  a => {
    val o = new PGobject
    o.setType("json")
    o.setValue(a.noSpaces)
    o
  }
)

我不知道如何处理这种情况。

【问题讨论】:

    标签: scala spray-json


    【解决方案1】:

    最后,我想出了这个:

     implicit val jsonMeta: Meta[JsValue] =
    Meta[String].timap[JsValue](
      str => str.parseJson)( jsVal => jsVal.prettyPrint)
    

    【讨论】:

      猜你喜欢
      • 2014-11-13
      • 2015-12-15
      • 2011-02-23
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 2013-05-31
      相关资源
      最近更新 更多