Skip to content

QuickAvroLoad

Cinchoo edited this page Feb 28, 2021 · 1 revision

Loading JSON file

To load Avro file, use ChoAvroReader component to parse it. Sample below shows how to load Avro file (Emp.avro)

(Avro is binary format, sample shows the payload in JSON format for illustration purpose)

[
    {
    "Id": 1,
    "Name": "Mark"
    },
    {
    "Id": 2,
    "Name": "Tom"
    }
]

Load using POCO object

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
}
foreach (var e in new ChoAvroReader<Employee>("Emp.avro"))
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);

Load using loop

var reader = new ChoAvroReader<Employee>("Emp.avro");
Employee rec;
 
while ((rec = reader.Read()) != null)
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);