I have found some code here https://learn.microsoft.com/en-us/azure/hdinsight/hdinsight-dotnet-avro-serialization#Scenario2 that does the reverse of what I need:
//Define the schema in JSON
const string Schema = @"{
""type"":""record"",
""name"":""Microsoft.Hadoop.Avro.Specifications.SensorData"",
""fields"":
[
{
""name"":""Location"",
""type"":
{
""type"":""record"",
""name"":""Microsoft.Hadoop.Avro.Specifications.Location"",
""fields"":
[
{ ""name"":""Floor"", ""type"":""int"" },
{ ""name"":""Room"", ""type"":""int"" }
]
}
},
{ ""name"":""Value"", ""type"":""bytes"" }
]
}";
//Create a generic serializer based on the schema
var serializer = AvroSerializer.CreateGeneric(Schema);
I would like to take a model that I have created:
[DataContract(Name = "Demo", Namespace = "pubsub.demo")]
public class Demo
{
[DataMember(Name = "value")]
public long Value { get; set; }
}
...and serialize this C# model into a JSON AVRO Schema string.
Reason:
I only want to maintain C# models and automatically register these models with Confluent's Schema Registry. To register with schema registry the schema needs to be in a JSON AVRO format (Just like Schema
above).
I would prefer not to have both the JSON defined and the C# model. If I had to maintian one, I would prefer to have a C# model.
ISpecificRecord
orGenericRecord
? Or those are still same byte arrays in message? – Howe