Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcin-jozefowicz opened this issue Jul 3, 2023 · 0 comments

Comments

@marcin-jozefowicz
Copy link

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

@marcin-jozefowicz marcin-jozefowicz changed the title Problem with namespace clashes for generic wrapper classess Problem with namespace clashes for generic wrapper classess | SchemaParseException: Can't redefine Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant