sbt-avrohugger
sbt-avrohugger copied to clipboard
How to deal with two classes with the same name
Hi,
first of all: great plugin! I'm trying to use it within the context of generating case classes for objects stored in Kafka messages. I have no direct way of modifying the schema, and of of those schemas has a nested record with the same name of the root record. Like so:
{
"type" : "record",
"name" : "Order",
"namespace" : "my.namespace1",
"fields" : [ {
"name" : "id",
"type" : "string"
}, {
"name" : "timestamp",
"type" : "long"
}, {
"name" : "source",
"type" : "string"
}, {
"name" : "type",
"type" : "string"
}, {
"name" : "payload",
"type" : {
"type" : "record",
"name" : "Order",
"namespace" : "my.namespace2",
"fields" : [
// some fields
]
}
}
When I use your plugin to generate the Scala class hierarchy, I end up with a top-level case class that looks like this:
/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */
package my.namespace1
import my.namespace2.Order
case class Order(id: String, timestamp: Long, source: String, `type`: String, payload: Order)
As you can see, the imported my.namespace2.Order
shadows the definition of the case class my.namespace1.Order
itself.
Any idea how to deal with this kind of situation?
Thank you very much for reporting this. I think a sensible solution would be to forego the cleanliness the imports, and use fully-qualified names the the type positions. While I don't expect the fix to be terribly involved, unfortunately my timeframe is uncertain, likely on a "months" scale.