Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify semi- and auto- derivation for jsoniter-scala #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmarks/src/main/scala/example/JsonRoundTrips.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class JsonRoundTrips extends JsonRoundTripPlatform {
@Benchmark
def circeMagnoliaSemi: Any = CirceMagnoliaSemi.roundTrip(out)

@Benchmark
def jsoniterScalaAuto: Any = JsoniterScalaAuto.roundTrip(out)

@Benchmark
def jsoniterScalaSemi: Any = JsoniterScalaSemi.roundTrip(out)
}
16 changes: 14 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ lazy val root = project
.aggregate(circeMagnoliaAuto.projectRefs *)
.aggregate(circeMagnoliaSemi.projectRefs *)
.aggregate(jsoniterScalaWrapper.projectRefs *)
.aggregate(jsoniterScalaAuto.projectRefs *)
.aggregate(jsoniterScalaSanely.projectRefs *)
.aggregate(jsoniterScalaSemi.projectRefs *)

Expand Down Expand Up @@ -249,13 +250,23 @@ lazy val jsoniterScalaSanely = projectMatrix
.settings(commonSettings *)
.dependsOn(testClasses, jsoniterScalaWrapper)

lazy val jsoniterScalaAuto = projectMatrix
.in(file("jsoniter-scala-auto"))
.someVariations(versions.scalas, versions.platforms)(only1VersionInIDE *)
.settings(commonSettings *)
.settings(
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.30.11",
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.30.11"
)
.dependsOn(testClasses)

lazy val jsoniterScalaSemi = projectMatrix
.in(file("jsoniter-scala-semi"))
.someVariations(versions.scalas, versions.platforms)(only1VersionInIDE *)
.settings(commonSettings *)
.settings(
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.30.9",
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.30.9"
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.30.11",
libraryDependencies += "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.30.11"
)
.dependsOn(testClasses)

Expand All @@ -276,6 +287,7 @@ lazy val benchmarks = projectMatrix
circeGenericSemi,
circeMagnoliaAuto,
circeMagnoliaSemi,
jsoniterScalaAuto,
jsoniterScalaSemi
)
.enablePlugins(JmhPlugin)
21 changes: 21 additions & 0 deletions jsoniter-scala-auto/src/main/scala/example/JsoniterScalaAuto.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package example

import example.model1.*
import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

object JsoniterScalaAuto {
implicit private val outCodec: JsonValueCodec[Out] = JsonCodecMaker.make

def roundTrip(out: Out): (String, Either[Throwable, Out]) = {
val str = writeToString(out)
val parsed = scala.util.Try(readFromString(str)).toEither
str -> parsed
}

def main(args: Array[String]): Unit = {
val (json, parsed) = roundTrip(Out.example)
println(json)
println(parsed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

object JsoniterScalaSemi {

implicit private val outCodec: JsonValueCodec[Out] =
JsonCodecMaker.make(CodecMakerConfig.withAllowRecursiveTypes(true))
implicit private val in1Codec: JsonValueCodec[In1] = JsonCodecMaker.make
implicit private val in2Codec: JsonValueCodec[In2] = JsonCodecMaker.make
implicit private val in3Codec: JsonValueCodec[In3] = JsonCodecMaker.make
implicit private val in4Codec: JsonValueCodec[In4] = JsonCodecMaker.make
implicit private val in5Codec: JsonValueCodec[In5] = JsonCodecMaker.make
implicit private val outCodec: JsonValueCodec[Out] = JsonCodecMaker.make

def roundTrip(out: Out): (String, Either[Throwable, Out]) = {
val str = writeToString(out)
val parsed = scala.util.Try(readFromString(str)).toEither
val parsed = scala.util.Try(readFromString[Out](str)).toEither
str -> parsed
}

Expand Down