From b21368434cdc7305aa1c2f9e10a75842b0ff7e4c Mon Sep 17 00:00:00 2001 From: Lucas Satabin Date: Wed, 7 Feb 2024 16:24:02 +0100 Subject: [PATCH] Add circe based (de)serializers --- build.sbt | 10 +++++++--- .../scala/de/commercetools/queue/circe.scala | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 circe/src/main/scala/de/commercetools/queue/circe.scala diff --git a/build.sbt b/build.sbt index 60f7cee..46b387d 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,7 @@ val Scala213 = "2.13.12" ThisBuild / crossScalaVersions := Seq(Scala213, "3.3.1") ThisBuild / scalaVersion := Scala213 -lazy val root = tlCrossRootProject.aggregate(core, azureServiceBus) +lazy val root = tlCrossRootProject.aggregate(core, azureServiceBus, circe) val commonSettings = List( libraryDependencies ++= Seq( @@ -32,14 +32,18 @@ lazy val core = crossProject(JVMPlatform) name := "cloud-queues-core" ) -lazy val queuesCirce = crossProject(JVMPlatform) +lazy val circe = crossProject(JVMPlatform) .crossType(CrossType.Pure) .in(file("circe")) .enablePlugins(NoPublishPlugin) .settings(commonSettings) .settings( - name := "cloud-queues-circe" + name := "cloud-queues-circe", + libraryDependencies ++= List( + "io.circe" %%% "circe-parser" % Versions.circe + ) ) + .dependsOn(core) lazy val azureServiceBus = crossProject(JVMPlatform) .crossType(CrossType.Pure) diff --git a/circe/src/main/scala/de/commercetools/queue/circe.scala b/circe/src/main/scala/de/commercetools/queue/circe.scala new file mode 100644 index 0000000..5fbd66f --- /dev/null +++ b/circe/src/main/scala/de/commercetools/queue/circe.scala @@ -0,0 +1,17 @@ +package de.commercetools.queue + +import cats.effect.IO +import cats.syntax.either._ +import io.circe.parser.parse +import io.circe.syntax._ +import io.circe.{Decoder, Encoder} + +object circe { + + implicit def serializerForEncoder[T: Encoder]: Serializer[T] = + _.asJson.noSpaces + + implicit def deserializerForDecoder[T: Decoder]: Deserializer[T] = + parse(_).flatMap(_.as[T]).liftTo[IO] + +}