zio/zio-json

Refined interop should include additional Validate instances

gnp opened this issue · 0 comments

gnp commented

It is not possible to do this with zio-json-interop-refined:JsonDecoder[ast.Json.Obj Refined Empty]. This is because the Empty validation requires the target to implement Iterable, and ast.Json.Obj does not. There may be other cases for the types under ast.Json.* where a natural validation doesn't work.

For the specific case above, I had to add this to my code to get it to work:

  import eu.timepit.refined.api.Validate
  implicit def emptyObjValidate: Validate.Plain[ast.Json.Obj, Empty] =
    Validate
      .fromPredicate[ast.Json.Obj, Empty](t => t.isEmpty, t => s"isEmpty(keys: ${t.keys.mkString(", ")})", Empty())