julianpeeters / avrohugger

Generate Scala case class definitions from Avro schemas
Apache License 2.0
202 stars 120 forks source link

Scalac warns about "match may not be exhaustive" for specific record with map type #166

Open mkuthan opened 1 year ago

mkuthan commented 1 year ago

If project defines restrictive Scala flags like -Xfatal-warnings the compilation of generated specific records fail if there is a map in the schema.

SampleAvroClass.scala:69:9: match may not be exhaustive.
It would fail on the following input: (x: Any forSome x not in java.util.Map[?,?])

Corresponding fragment of the generated specific record:

case 4 => this.mapField = {
  value match {
    case (map: java.util.Map[_,_]) => {
      scala.jdk.CollectionConverters.MapHasAsScala(map).asScala.toMap map { kvp =>
        val key = kvp._1.toString
        val value = kvp._2
        (key, value.toString)
      }
    }
  }
}.asInstanceOf[Map[String, String]]

I would opt for adding unchecked annotation in the generated code.