Skip to content

Commit 25340a7

Browse files
committed
Add missing support of arrays with opaque type values
1 parent a37b0c0 commit 25340a7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ object JsonCodecMaker {
774774
!flags.is(Flags.Abstract) && !flags.is(Flags.JavaDefined) && !flags.is(Flags.Trait)
775775
}
776776

777+
def isOpaque(tpe: TypeRepr): Boolean = tpe.typeSymbol.flags.is(Flags.Opaque)
778+
777779
def isSealedClass(tpe: TypeRepr): Boolean = tpe.typeSymbol.flags.is(Flags.Sealed)
778780

779781
def hasSealedParent(tpe: TypeRepr): Boolean =
@@ -2263,7 +2265,7 @@ object JsonCodecMaker {
22632265
val tpe1 = typeArg1(tpe)
22642266
val newArrayOnChange = tpe1 match
22652267
case AppliedType(_, _) => true
2266-
case _ => isValueClass(tpe1)
2268+
case _ => isValueClass(tpe1) || isOpaque(tpe1)
22672269
tpe1.asType match
22682270
case '[t1] =>
22692271
def growArray(x: Expr[Array[t1]], i: Expr[Int], l: Expr[Int])(using Quotes): Expr[Array[t1]] =

jsoniter-scala-macros/shared/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerNewTypeSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class JsonCodecMakerNewTypeSpec extends VerifyingSpec {
114114
val nullValue: Year = null.asInstanceOf[Year]
115115
}
116116
verifySerDeser(make[Period], Period(Year.from(1976), Year.from(2022)), """{"start":1976,"end":2022}""")
117+
verifySerDeser(make[Array[Year]], Array(Year(1976).get), "[1976]")
117118
}
118119
"serialize and deserialize a Scala3 union type using a custom codec" in {
119120
type Value = String | Boolean | Double

0 commit comments

Comments
 (0)