Skip to content

Commit 68a884d

Browse files
committed
Fixed names for terms of Scala 3 enumerations used ADT leaf class name mapper to be full names
1 parent 4275de3 commit 68a884d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,11 +1538,7 @@ object JsonCodecMaker {
15381538
namedValueOpt(named.headOption, tpe).get
15391539
} else cfg.adtLeafClassNameMapper({
15401540
if (tpe =:= TypeRepr.of[None.type]) "scala.None"
1541-
else if (isEnum) {
1542-
tpe match
1543-
case TermRef(_, name) => name
1544-
case _ => fail(s"Unsupported enum type: '${tpe.show}', tree=$tpe")
1545-
} else if (tpe.typeSymbol.flags.is(Flags.Module)) tpe.termSymbol.fullName
1541+
else if (isEnum || tpe.typeSymbol.flags.is(Flags.Module)) tpe.termSymbol.fullName
15461542
else tpe.typeSymbol.fullName
15471543
}).getOrElse(fail(s"Discriminator is not defined for ${tpe.show}"))
15481544

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class JsonCodecMakerNewEnumSpec extends VerifyingSpec {
9898
case "Green" => "🟩"
9999
}).withDiscriminatorFieldName(None)),
100100
List(TrafficLight.Red, TrafficLight.Yellow, TrafficLight.Green), """["🟥","🟨","🟩"]""")
101+
verifySerDeser(make[List[TrafficLight]](CodecMakerConfig
102+
.withAdtLeafClassNameMapper(x => x).withDiscriminatorFieldName(None)),
103+
List(TrafficLight.Red, TrafficLight.Yellow, TrafficLight.Green),
104+
"""["com.github.plokhotnyuk.jsoniter_scala.macros.TrafficLight$.Red","com.github.plokhotnyuk.jsoniter_scala.macros.TrafficLight$.Yellow","com.github.plokhotnyuk.jsoniter_scala.macros.TrafficLight$.Green"]""")
101105
}
102106
"serialize and deserialize Scala3 enums that extend java.lang.Enum" in {
103107
verifySerDeser(make[List[Java]],

0 commit comments

Comments
 (0)