Skip to content

Commit 8a9bde1

Browse files
committed
Update zio-json to 0.7.36
1 parent f17f354 commit 8a9bde1

File tree

10 files changed

+65
-62
lines changed

10 files changed

+65
-62
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)
243243
"com.disneystreaming.smithy4s" %%% "smithy4s-json" % "0.18.29",
244244
"com.evolutiongaming" %%% "play-json-jsoniter" % "0.10.3" intransitive(),
245245
"org.playframework" %%% "play-json" % "3.0.4",
246-
"dev.zio" %%% "zio-json" % "0.7.26",
246+
"dev.zio" %%% "zio-json" % "0.7.36",
247247
"dev.zio" %%% "zio-schema-json" % "1.6.3",
248248
"io.circe" %%% "circe-generic" % "0.14.10",
249249
"io.circe" %%% "circe-jawn" % "0.14.10",

jsoniter-scala-benchmark/js/src/main/scala-2/com/github/plokhotnyuk/jsoniter_scala/benchmark/Main.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1654,8 +1654,7 @@ object Main {
16541654
B("playJsonJsoniter")(benchmark.playJsonJsoniter()),
16551655
B("smithy4sJson")(benchmark.smithy4sJson()),
16561656
B("uPickle")(benchmark.uPickle()),
1657-
//FIXME: zio-json skips serialization of the `"description": {}` field
1658-
//B("zioJson")(benchmark.zioJson()),
1657+
B("zioJson")(benchmark.zioJson()),
16591658
B("zioSchemaJson")(benchmark.zioSchemaJson())
16601659
))
16611660
}, {

jsoniter-scala-benchmark/js/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/benchmark/Main.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,7 @@ object Main {
15381538
B("playJsonJsoniter")(benchmark.playJsonJsoniter()),
15391539
B("smithy4sJson")(benchmark.smithy4sJson()),
15401540
B("uPickle")(benchmark.uPickle()),
1541-
//FIXME: zio-json skips serialization of the `"description": {}` field
1542-
//B("zioJson")(benchmark.zioJson()),
1541+
B("zioJson")(benchmark.zioJson()),
15431542
B("zioSchemaJson")(benchmark.zioSchemaJson())
15441543
))
15451544
}, {

jsoniter-scala-benchmark/js/src/test/scala-2/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWritingSpec.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class TwitterAPIWritingSpec extends BenchmarkSpecBase {
1818
toString(b.playJsonJsoniter()) shouldBe b.compactJsonString1
1919
toString(b.smithy4sJson()) shouldBe b.compactJsonString1
2020
toString(b.uPickle()) shouldBe b.compactJsonString1
21-
//FIXME: zio-json skips serialization of the `"description": {}` field
22-
//toString(b.zioJson()) shouldBe b.compactJsonString1
21+
toString(b.zioJson()) shouldBe b.compactJsonString1
2322
toString(b.zioSchemaJson()) shouldBe b.compactJsonString1
2423
}
2524
}

jsoniter-scala-benchmark/js/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWritingSpec.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class TwitterAPIWritingSpec extends BenchmarkSpecBase {
1717
toString(b.playJsonJsoniter()) shouldBe b.compactJsonString1
1818
toString(b.smithy4sJson()) shouldBe b.compactJsonString1
1919
toString(b.uPickle()) shouldBe b.compactJsonString1
20-
//FIXME: zio-json skips serialization of the `"description": {}` field
21-
//toString(b.zioJson()) shouldBe b.compactJsonString1
20+
toString(b.zioJson()) shouldBe b.compactJsonString1
2221
toString(b.zioSchemaJson()) shouldBe b.compactJsonString1
2322
}
2423
}

jsoniter-scala-benchmark/jvm/src/test/scala-2/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWritingSpec.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class TwitterAPIWritingSpec extends BenchmarkSpecBase {
2727
toString(b.sprayJson()) shouldBe b.compactJsonString2
2828
toString(b.uPickle()) shouldBe b.compactJsonString1
2929
toString(b.weePickle()) shouldBe b.compactJsonString1
30-
//FIXME: zio-json skips serialization of the `"description": {}` field
31-
//toString(b.zioJson()) shouldBe b.compactJsonString1
30+
toString(b.zioJson()) shouldBe b.compactJsonString1
3231
toString(b.zioSchemaJson()) shouldBe b.compactJsonString1
3332
}
3433
}

jsoniter-scala-benchmark/jvm/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWritingSpec.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class TwitterAPIWritingSpec extends BenchmarkSpecBase {
2424
toString(b.sprayJson()) shouldBe b.compactJsonString2
2525
toString(b.uPickle()) shouldBe b.compactJsonString1
2626
toString(b.weePickle()) shouldBe b.compactJsonString1
27-
//FIXME: zio-json skips serialization of the `"description": {}` field
28-
//toString(b.zioJson()) shouldBe b.compactJsonString1
27+
toString(b.zioJson()) shouldBe b.compactJsonString1
2928
toString(b.zioSchemaJson()) shouldBe b.compactJsonString1
3029
}
3130
}

jsoniter-scala-benchmark/shared/src/main/scala-2/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWriting.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class TwitterAPIWriting extends TwitterAPIBenchmark {
138138

139139
FromScala(obj).transform(ToJson.bytes)
140140
}
141-
/* FIXME: zio-json skips serialization of the `"description": {}` field
141+
142142
@Benchmark
143143
def zioJson(): Array[Byte] = {
144144
import com.github.plokhotnyuk.jsoniter_scala.benchmark.ZioJsonCodecs._
@@ -147,7 +147,7 @@ class TwitterAPIWriting extends TwitterAPIBenchmark {
147147

148148
obj.toJson.getBytes(UTF_8)
149149
}
150-
*/
150+
151151
@Benchmark
152152
def zioSchemaJson(): Array[Byte] = {
153153
import com.github.plokhotnyuk.jsoniter_scala.benchmark.ZioSchemaJsonCodecs._

jsoniter-scala-benchmark/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/benchmark/TwitterAPIWriting.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class TwitterAPIWriting extends TwitterAPIBenchmark {
122122

123123
FromScala(obj).transform(ToJson.bytes)
124124
}
125-
/* FIXME: zio-json skips serialization of the `"description": {}` field
125+
126126
@Benchmark
127127
def zioJson(): Array[Byte] = {
128128
import com.github.plokhotnyuk.jsoniter_scala.benchmark.ZioJsonCodecs._
@@ -131,7 +131,7 @@ class TwitterAPIWriting extends TwitterAPIBenchmark {
131131

132132
obj.toJson.getBytes(UTF_8)
133133
}
134-
*/
134+
135135
@Benchmark
136136
def zioSchemaJson(): Array[Byte] = {
137137
import com.github.plokhotnyuk.jsoniter_scala.benchmark.ZioSchemaJsonCodecs._

jsoniter-scala-benchmark/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/benchmark/ZioJsonCodecs.scala

+54-45
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package com.github.plokhotnyuk.jsoniter_scala.benchmark
22

33
import com.github.plokhotnyuk.jsoniter_scala.benchmark.SuitEnum.SuitEnum
44
import zio.json.JsonDecoder.JsonError
5-
import zio.json.internal.Lexer.{NumberMaxBits, error}
6-
import zio.json.internal.{Lexer, RetractReader, StringMatrix, UnsafeNumbers, Write}
5+
import zio.json.internal.Lexer.error
6+
import zio.json.internal.{Lexer, RetractReader, SafeNumbers, StringMatrix, UnsafeNumbers, Write}
77
import zio.json.{DeriveJsonCodec, ExplicitEmptyCollections, JsonCodec, JsonCodecConfiguration, JsonDecoder, JsonEncoder}
8-
98
import java.util.Base64
10-
import scala.collection.immutable.ArraySeq
119

1210
object ZioJsonCodecs {
13-
implicit val config: JsonCodecConfiguration =
14-
JsonCodecConfiguration(explicitEmptyCollections = ExplicitEmptyCollections(encoding = false, decoding = false))
11+
implicit val config: JsonCodecConfiguration = JsonCodecConfiguration(
12+
explicitEmptyCollections = ExplicitEmptyCollections(encoding = false, decoding = false),
13+
enumValuesAsStrings = true
14+
)
1515
implicit val adtC3c: JsonCodec[ADTBase] = DeriveJsonCodec.gen
1616
implicit val geoJsonC3c: JsonCodec[GeoJSON.GeoJSON] = {
1717
implicit val c1: JsonCodec[GeoJSON.SimpleGeometry] = DeriveJsonCodec.gen
@@ -73,14 +73,37 @@ object ZioJsonCodecs {
7373
genTwitterAPIC3c
7474
}
7575
implicit val anyValsC3cr: JsonCodec[AnyVals] = {
76-
implicit val c1: JsonCodec[ByteVal] = JsonCodec.byte.transform(ByteVal.apply, _.a)
77-
implicit val c2: JsonCodec[ShortVal] = JsonCodec.short.transform(ShortVal.apply, _.a)
78-
implicit val c3: JsonCodec[IntVal] = JsonCodec.int.transform(IntVal.apply, _.a)
79-
implicit val c4: JsonCodec[LongVal] = JsonCodec.long.transform(LongVal.apply, _.a)
80-
implicit val c5: JsonCodec[BooleanVal] = JsonCodec.boolean.transform(BooleanVal.apply, _.a)
81-
implicit val c6: JsonCodec[CharVal] = JsonCodec.char.transform(CharVal.apply, _.a)
82-
implicit val c7: JsonCodec[DoubleVal] = JsonCodec.double.transform(DoubleVal.apply, _.a)
83-
implicit val c8: JsonCodec[FloatVal] = JsonCodec.float.transform(FloatVal.apply, _.a)
76+
implicit val c1: JsonCodec[ByteVal] = new JsonCodec[ByteVal](
77+
(a: ByteVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a.toInt, out),
78+
(trace: List[JsonError], in: RetractReader) => new ByteVal(Lexer.byte(trace, in)))
79+
implicit val c2: JsonCodec[ShortVal] = new JsonCodec[ShortVal](
80+
(a: ShortVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a.toInt, out),
81+
(trace: List[JsonError], in: RetractReader) => new ShortVal(Lexer.short(trace, in)))
82+
implicit val c3: JsonCodec[IntVal] = new JsonCodec[IntVal](
83+
(a: IntVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a, out),
84+
(trace: List[JsonError], in: RetractReader) => new IntVal(Lexer.int(trace, in)))
85+
implicit val c4: JsonCodec[LongVal] = new JsonCodec[LongVal](
86+
(a: LongVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a, out),
87+
(trace: List[JsonError], in: RetractReader) => new LongVal(Lexer.long(trace, in)))
88+
implicit val c5: JsonCodec[BooleanVal] = new JsonCodec[BooleanVal](
89+
(a: BooleanVal, _: Option[Int], out: Write) => {
90+
if (a.a) out.write('t', 'r', 'u', 'e')
91+
else out.write('f', 'a', 'l', 's', 'e')
92+
},
93+
(trace: List[JsonError], in: RetractReader) => new BooleanVal(Lexer.boolean(trace, in)))
94+
implicit val c6: JsonCodec[CharVal] = new JsonCodec[CharVal](
95+
(a: CharVal, _: Option[Int], out: Write) => {
96+
out.write('"')
97+
out.write(a.a)
98+
out.write('"')
99+
},
100+
(trace: List[JsonError], in: RetractReader) => new CharVal(Lexer.char(trace, in)))
101+
implicit val c7: JsonCodec[DoubleVal] = new JsonCodec[DoubleVal](
102+
(a: DoubleVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a, out),
103+
(trace: List[JsonError], in: RetractReader) => new DoubleVal(Lexer.double(trace, in)))
104+
implicit val c8: JsonCodec[FloatVal] = new JsonCodec[FloatVal](
105+
(a: FloatVal, _: Option[Int], out: Write) => SafeNumbers.write(a.a, out),
106+
(trace: List[JsonError], in: RetractReader) => new FloatVal(Lexer.float(trace, in)))
84107
DeriveJsonCodec.gen
85108
}
86109
val base64C3c: JsonCodec[Array[Byte]] = new JsonCodec[Array[Byte]](
@@ -91,7 +114,7 @@ object ZioJsonCodecs {
91114
},
92115
(trace: List[JsonError], in: RetractReader) => Base64.getDecoder.decode(Lexer.string(trace, in).toString))
93116
val bigDecimalC3c: JsonCodec[BigDecimal] = new JsonCodec[BigDecimal](
94-
(a: BigDecimal, _: Option[Int], out: Write) => out.write(a.toString),
117+
(a: BigDecimal, _: Option[Int], out: Write) => SafeNumbers.write(a.bigDecimal, out),
95118
(trace: List[JsonError], in: RetractReader) => {
96119
try {
97120
val i = UnsafeNumbers.bigDecimal_(in, false, Int.MaxValue)
@@ -102,7 +125,10 @@ object ZioJsonCodecs {
102125
}
103126
})
104127
val bigIntC3c: JsonCodec[BigInt] = new JsonCodec[BigInt](
105-
(a: BigInt, _: Option[Int], out: Write) => out.write(a.toString),
128+
(a: BigInt, _: Option[Int], out: Write) => {
129+
if (a.isValidLong) SafeNumbers.write(a.longValue, out)
130+
else SafeNumbers.write(a.bigInteger, out)
131+
},
106132
(trace: List[JsonError], in: RetractReader) => {
107133
try {
108134
val i = BigInt(UnsafeNumbers.bigInteger_(in, false, Int.MaxValue))
@@ -133,36 +159,19 @@ object ZioJsonCodecs {
133159
}
134160
implicit val missingRequiredFieldsC3c: JsonCodec[MissingRequiredFields] = DeriveJsonCodec.gen
135161
implicit val primitivesC3c: JsonCodec[Primitives] = DeriveJsonCodec.gen
136-
implicit val enumADTsC3c: JsonCodec[SuitADT] = new JsonCodec(new JsonEncoder[SuitADT] {
137-
override def unsafeEncode(a: SuitADT, indent: Option[Int], out: Write): Unit = {
162+
implicit val enumADTsC3c: JsonCodec[SuitADT] = DeriveJsonCodec.gen
163+
implicit val enumsC3c: JsonCodec[SuitEnum] = new JsonCodec(
164+
(a: SuitEnum, _: Option[Int], out: Write) => {
138165
out.write('"')
139166
out.write(a.toString)
140167
out.write('"')
141-
}
142-
}, new JsonDecoder[SuitADT] {
143-
private[this] val values = Array(Hearts, Spades, Diamonds, Clubs)
144-
private[this] val matrix = new StringMatrix(values.map(_.toString))
145-
146-
override def unsafeDecode(trace: List[JsonError], in: RetractReader): SuitADT = {
147-
val idx = Lexer.enumeration(trace, in, matrix)
148-
if (idx == -1) Lexer.error("SuitADT", trace)
149-
values(idx)
150-
}
151-
})
152-
implicit val enumsC3c: JsonCodec[SuitEnum] = new JsonCodec(new JsonEncoder[SuitEnum] {
153-
override def unsafeEncode(a: SuitEnum, indent: Option[Int], out: Write): Unit = {
154-
out.write('"')
155-
out.write(a.toString)
156-
out.write('"')
157-
}
158-
}, new JsonDecoder[SuitEnum] {
159-
private[this] val values = SuitEnum.values.toArray
160-
private[this] val matrix = new StringMatrix(values.map(_.toString))
161-
162-
override def unsafeDecode(trace: List[JsonError], in: RetractReader): SuitEnum = {
163-
val idx = Lexer.enumeration(trace, in, matrix)
164-
if (idx == -1) Lexer.error("SuitEnum", trace)
165-
values(idx)
166-
}
167-
})
168+
}, {
169+
val values = SuitEnum.values.toArray
170+
val matrix = new StringMatrix(values.map(_.toString))
171+
(trace: List[JsonError], in: RetractReader) => {
172+
val idx = Lexer.enumeration(trace, in, matrix)
173+
if (idx < 0) Lexer.error("SuitEnum", trace)
174+
values(idx)
175+
}
176+
})
168177
}

0 commit comments

Comments
 (0)