簡體   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