简体   繁体   中英

How to serialize/deserialize an object to avro in c#

I was using json.net to serialize/deserialize a pojo class to json and then send it to rabbitmq.Now I want to do the same using binary data in apache avro format.How is it possible to serialize/deserialize an object in c#?

public class person
{
    public string FirstName   {  get;     set;   }
    public string LastName { get; set; }
    public byte[] toAvro()
    {

    }

    public void fromAvro(byte[] input)
    {

    }
}

The below code good for your problem.

byte[] avroFileContent = File.ReadAllBytes(fileName);
Dictionary<string, object> result = AvroConvert.Deserialize(avroFileContent);

//or if u know the model of the data
person(Your Type) result = AvroConvert.Deserialize<MyModel>(avroFileContent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM