繁体   English   中英

如何在 c# 中将 object 序列化/反序列化为 avro

[英]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)
    {

    }
}

下面的代码很适合您的问题。

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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