Skip to content

Problem with namespace clashes for generic wrapper classess | SchemaParseException: Can't redefine #538

Open
@marcin-jozefowicz

Description

@marcin-jozefowicz

Hi!

I don't know if this is the right place to ask a question, but lets try!

I tried to introduce some kind of generic wrapper, it occurs that there is namespace clash based on error message. Or maybe how I can model it differently ? (this is minimal code I have plenty of other V types )

Question: Is there any workaround which will make this working.

import vulcan.Codec
import vulcan.Codec.OptionCodec
import vulcan.generic._
import java.util.UUID

sealed trait MaybeValue[V]

object MaybeValue {
  case class Cleared[V]() extends MaybeValue[V]

  case class Modified[V](newValue: V) extends MaybeValue[V]

  implicit def c[T](implicit x: Codec[T]): Codec[MaybeValue[T]] =
    Codec.derive[MaybeValue[T]]

}

case class TaskUpdateState(
    id: Option[MaybeValue[Long]],
    description: Option[MaybeValue[String]]
)
object TaskUpdateState {
  implicit val c: Codec[TaskUpdateState] = Codec.derive
}

val schemaValue = Codec[TaskUpdateState].schema

println(schemaValue)

Error output:

org.apache.avro.SchemaParseException: Can't redefine: Playground.MaybeValue.Modified
	at org.apache.avro.Schema$Names.put(Schema.java:1586)
	at org.apache.avro.Schema$NamedSchema.writeNameRef(Schema.java:844)
	at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:1011)
	at org.apache.avro.Schema$UnionSchema.toJson(Schema.java:1278)
	at org.apache.avro.Schema$RecordSchema.fieldsToJson(Schema.java:1039)
	at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:1023)
	at org.apache.avro.Schema.toString(Schema.java:433)
	at org.apache.avro.Schema.toString(Schema.java:405)
	at org.apache.avro.Schema.toString(Schema.java:396)
	at java.base/java.lang.String.valueOf(String.java:4216)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
	at scala.collection.IterableOnceOps.addString(IterableOnce.scala:1221)
	at scala.collection.IterableOnceOps.addString$(IterableOnce.scala:1216)
	at scala.collection.AbstractIterator.addString(Iterator.scala:1300)
	at scala.collection.IterableOnceOps.mkString(IterableOnce.scala:1166)
	at scala.collection.IterableOnceOps.mkString$(IterableOnce.scala:1164)
	at scala.collection.AbstractIterator.mkString(Iterator.scala:1300)
	at scala.runtime.ScalaRunTime$._toString(ScalaRunTime.scala:156)
	at scala.util.Right.toString(Either.scala:471)
....	

Scastie link

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions