【问题标题】:How to serialize/deserialize an object to avro in c#如何在 C# 中将对象序列化/反序列化为 avro
【发布时间】:2019-10-22 10:18:30
【问题描述】:

我正在使用 json.net 将 pojo 类序列化/反序列化为 json,然后将其发送到 rabbitmq。现在我想使用 apache avro 格式的二进制数据来做同样的事情。如何序列化/反序列化一个对象在 c# 中?

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

    }

    public void fromAvro(byte[] input)
    {

    }
}

【问题讨论】:

  • 类似的问题还有很多。您是否尝试过在 SO 中搜索 c# avro 或在 NuGet 中搜索 avro? NuGet 中至少有 36 个包名称中包含 Avro

标签: c# avro avro-tools


【解决方案1】:

以下代码可以解决您的问题。

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

【讨论】:

猜你喜欢
  • 2018-10-11
  • 2020-07-19
  • 2018-05-27
  • 2018-07-17
  • 2020-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
相关资源
最近更新 更多