Support Questions

Find answers, ask questions, and share your expertise

Scala - not able to get schema from Avro class

Expert Contributor

I have an Avro generated class - com.avro.Person which has a method -> getClassSchema.

I’m passing className to a method, and in the method I need to get the Avro schema.

Here is the code I’m using:

val pr = Class.forName(productCls) // where productCls = classOf[Product].getName 

How do I call the method getClassSchema of this class ?

Additional Info :

Links to & Person.avsc




In, there is a method

public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } 

I'm trying to call this method to get the AVRO schema corresponding to class - Person Code

import com.avro.Person  
val m1 = Map("schema.class" -> classOf[Person].getName) 

This Map is passed onto a function .. say foo, and i'm trying to get the schema based on the class

def foo(m : Map[String, String]){
    val personClass = Map("schema.class")
    val pr = Class.forName(personClass) 
    //TBD - to get the schema of the avro class

Now using this "pr", i need to get the avro schema of the Person avro, hence i'm trying to call method getClassSchema, which returns the schema 

How do i do this  ?
any help on this is really appreciated.


Expert Contributor

@Timothy Spann - looping you in, any ideas on this ?