Skip to content

Commit

Permalink
More efficient decoding of case classes (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk authored Feb 3, 2025
1 parent e56066d commit 001cb09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions zio-json/shared/src/main/scala-2.x/zio/json/macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import zio.json.internal.{ FieldEncoder, Lexer, RetractReader, StringMatrix, Wri

import scala.annotation._
import scala.language.experimental.macros
import scala.reflect.ClassTag

/**
* If used on a case class field, determines the name of the JSON field. Defaults to the case class field name.
Expand Down
7 changes: 7 additions & 0 deletions zio-json/shared/src/main/scala-3/zio/json/macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import zio.json.ast.Json
import zio.json.internal.{ FieldEncoder, Lexer, RetractReader, StringMatrix, Write }

import scala.annotation._
import scala.collection.Factory
import scala.collection.mutable
import scala.language.experimental.macros

Expand Down Expand Up @@ -516,6 +517,9 @@ sealed class JsonDecoderDerivation(config: JsonCodecConfiguration) extends Deriv
private final class ArraySeq(p: Array[Any]) extends IndexedSeq[Any] {
def apply(i: Int): Any = p(i)
def length: Int = p.length
override def to[A](factory: Factory[Any, A]): A =
if (factory.isInstanceOf[Factory[Any, Array[Any]]]) p.asInstanceOf[A]
else super.to(factory)
}
}

Expand All @@ -540,6 +544,9 @@ object DeriveJsonDecoder extends JsonDecoderDerivation(JsonCodecConfiguration.de
private final class ArraySeq(p: Array[Any]) extends IndexedSeq[Any] {
def apply(i: Int): Any = p(i)
def length: Int = p.length
override def to[A](factory: Factory[Any, A]): A =
if (factory.isInstanceOf[Factory[Any, Array[Any]]]) p.asInstanceOf[A]
else super.to(factory)
}
}

Expand Down

0 comments on commit 001cb09

Please sign in to comment.