I am trying to learn Apache Avro and I have started with simple tutorial for Avro. I am trying to use a JSON Schema to load the data. Below is my Simple example-
public class AvroExample {
public static Schema SCHEMA; // writer's schema
public static Schema SCHEMA2; // reader's schema
private String name;
private int age;
private String[] mails;
private AvroExample boss;
static {
try {
SCHEMA = Schema.parse(AvroExample.class.getResourceAsStream("Employee.avsc"));
SCHEMA2 = Schema.parse(AvroExample.class.getResourceAsStream("Employee2.avsc"));
} catch (Exception e) {
System.out.println("Couldn't load a schema: " + e.getMessage());
}
}
// some more code
}
But somehow this line, always give me exception-
SCHEMA = Schema.parse(AvroExample.class.getResourceAsStream("Employee.avsc"));
as- Couldn't load a schema: java.lang.NullPointerException
I believe somehow, it is not able to load the file properly or I am loading the file in a wrong way.
This is the file content-
{
"type": "record",
"name": "Employee",
"fields": [
{"name": "name", "type": "string"},
{"name": "age", "type": "int"},
{"name": "emails", "type": {"type": "array", "items": "string"}},
{"name": "boss", "type": ["Employee","null"]}
]
}
Below is the picture of my workspace which shows where I have put those two avsc files-
Can anybody help me with this?