1

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

    }
}
Behdad
  • 184
  • 3
  • 12
  • There are a lot of similar questions. Have you tried searching for `c# avro` in SO, or `avro` in NuGet? There are at least 36 packages in NuGet with `Avro` in their name. – Panagiotis Kanavos Oct 22 '19 at 10:26

1 Answers1

0

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);
Metin Atalay
  • 1,375
  • 18
  • 28
  • I encountered some problems with this library and looking for an official or reliable solution. – Behdad Oct 22 '19 at 15:04
  • 2
    Apache.Avro is the official Apache NuGet package: https://www.nuget.org/packages/Apache.Avro/. It is identified as such in the C# README in the official Apache Avro GitHub project: https://github.com/apache/avro/blob/master/lang/csharp/README.md. Unfortunately, there's not much as far as good how-to documentation for the C# library at this time. If you are familiar with the Java library, you will probably be able to pick it up fairly quickly. – blachniet Oct 23 '19 at 01:07