diff --git a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala index b4193ba..519b8c7 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/ConfigurationMacroUtils.scala @@ -689,7 +689,7 @@ trait ConfigurationMacroUtils: ) ) - val discriminators: List[Term] = getAllChildren(tpe).map { + val discriminators: List[Term] = getAllChildren(tpe).distinct.map { case tpe: TypeRef => Select(stub(tpe), symbol) case tpe: TermRef => diff --git a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala index 688c9bc..234ae70 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala @@ -149,7 +149,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) ): Expr[JsonObjectWriter[T]] = val tpe = TypeRepr.of[T] val parsedConfig = parseSumConfig[T] - val types = getAllChildren(tpe) + val types = getAllChildren(tpe).distinct val (missingWriters, refs) = deriveMissingWritersForSum(types) val mirror = '{ summonInline[Mirror.SumOf[T]] } val writer = Block( @@ -492,7 +492,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) def deriveJsonReaderForSum[T: Type]: Expr[JsonReader[T]] = val tpe = TypeRepr.of[T] val parsed = parseSumConfig[T] - val children = getAllChildren(tpe) + val children = getAllChildren(tpe).distinct parsed.discriminator match case Some(DiscriminatorConfig(label, tpe, discriminators)) => tpe.asType match