Hi Tim,
PGObjects can be casted to JSON objects in two ways:
- Simply changing expected delivery type during the table is obtained by using get query. Somewhat like this:
val sql = s"select row_to_json(t)::text as result from tablename;"
2. Implicit conversion in scope of code
implicit val columnToJsValue:Column[JsValue] =
anorm.Column.nonNull[JsValue] { (value, meta) => val MetaDataItem(qualified, nullable, clazz)=
meta value match {
case json: org.postgresql.util.PGobject=>Right(Json.parse(json.getValue))
case _ => Left(TypeDoesNotMatch(s"Cannot convert $value: ${value.asInstanceOf[AnyRef].getClass} to Json for column $qualified"))
}
}
In addition to jsondecode, a preprocessing step of getting data and removing an extra encapsulation of data in the object might help, implying inspecting the data inside the PGObject and putting it in place of the parameter column in the table.
Hope this helps.