Skip to content

Commit

Permalink
Add circe based (de)serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
satabin committed Feb 7, 2024
1 parent 0f63ad5 commit b213684
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 7 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions circe/src/main/scala/de/commercetools/queue/circe.scala
Original file line number Diff line number Diff line change
@@ -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]

}

0 comments on commit b213684

Please sign in to comment.