Custom meta-mapping for spray JsValue

84 Views Asked by At

I need to create a meta for a spray.json.JsValue (which is actually an Option[JsValue] in my model class) for inserting it in a table with a JSON field. I tried to follow the doobie doc regarding custom mapping/JSON mapping, so I have this:

  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
  }
)

I don't know how to treat this case.

1

There are 1 best solutions below

0
Claudiu Scurtu On

Eventually, I came up with this:

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