AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
97 stars 27 forks source link

Serialize object/dynamic from type #141

Closed WevertonFelipeFerreira closed 4 months ago

WevertonFelipeFerreira commented 7 months ago

Describe implementation idea I would like to serialize my class with some typed fields (string, int, List or List) to the right avro types dynamically. I noticed that today we are unable to do this with "AvroConvert.Serializer()" and I would even like to know if this feature is already present.

In my test, I used this class

public class MyClass
{
    public string? Id { get;set;}
    public object? Name { get; set; }
}

var myClass= new MyClass();

myClass.Name = "test";
var serialized1 = AvroConvert.Serialize(myClass);

myClass.Name = new List<String>(){ "test", "test2" }
var serialized2 = AvroConvert.Serialize(myClass);

Name can be a string? or a List<string>? and I would like to automatically serialize to the right avro type/schema without needing to type the property in my class like string? name1 and List<string>? name2

Describe implementation idea I think we could add validations to the function that generates the avro schema.

AdrianStrugala commented 7 months ago

Hey @WevertonFelipeFerreira Thank you for your idea. As avro represents defined types according to the specification I am not sure what could be the representation of an object. Do you have an idea? Best, Adrian

github-actions[bot] commented 4 months ago

Closed due to inactivity.