Skip to content

Commit 8376590

Browse files
committed
add testing inOut for array json
1 parent 06da670 commit 8376590

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

modules/postgres-circe/src/main/scala/doobie/postgres/circe/Instances.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ object Instances {
3535
parse(a.getValue).leftMap(_.show))
3636

3737
implicit val arrayJsonGet: Get[Array[Json]] =
38-
Get.Advanced.array[PGobject](NonEmptyList.of("jsonb[]", "_jsonb"))
39-
.map(_.map(pgObj => parse(pgObj.getValue).fold(throw _, identity)))
38+
Get.Advanced.array[String](NonEmptyList.of("jsonb[]", "_jsonb"))
39+
.map(_.map(jsonStr => parse(jsonStr).fold(throw _, identity)))
4040

4141
implicit val arrayJsonPut: Put[Array[Json]] =
4242
Put.Advanced.array[String](NonEmptyList.of("jsonb", "jsonb[]", "json[]", "_jsonb"), "jsonb")
4343
.tcontramap(_.map(_.noSpaces))
4444

45+
implicit val listJsonGet: Get[List[Json]] =
46+
arrayJsonGet.map(_.toList)
47+
48+
implicit val listJsonPut: Put[List[Json]] =
49+
arrayJsonPut.contramap(_.toArray)
50+
4551
def pgEncoderPutT[A: Encoder]: Put[A] =
4652
Put[Json].tcontramap(_.asJson)
4753

modules/postgres-circe/src/test/scala/doobie/postgres/circe/PGJsonSuite.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class PGJsonSuite extends munit.CatsEffectSuite {
4848
testInOut("jsonb", Json.obj("something" -> Json.fromString("Yellow")), xa)
4949
}
5050

51+
{
52+
import doobie.postgres.circe.jsonb.implicits.*
53+
testInOut("jsonb[]", List(Json.obj("a" -> Json.fromInt(1)), Json.obj("b" -> Json.fromInt(2))), xa)
54+
}
55+
5156
// Explicit Type Checks
5257

5358
test("json should check ok for read") {

0 commit comments

Comments
 (0)