AdrianStrugala / AvroConvert

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

Avro2Json different output #126

Closed AlbertoMonteiro closed 8 months ago

AlbertoMonteiro commented 8 months ago

Describe the solution you'd like Given this model

public record Person(string Name, string? LastName);

When I do this

var bytes = AvroConvert.Serialize(new Person("Alberto", "Xpto"));
Console.WriteLine(AvroConvert.Avro2Json(bytes));

I get

{"Name":"Alberto","LastName":"Xpto"}

I am using GCP PubSub and it doesnt accept that json when I use GPC UI, I need this json to work

{"Name":"Alberto","LastName": { "string": "Xpto" }}

Describe implementation idea Is there any way using this lib to get this other json?

AdrianStrugala commented 8 months ago

Hello, I have used some external tool to produce a C# model from the other json and it created the following model:

    public class LastName
    {
        public string @string { get; set; }
    }

    public class Person
    {
        public string Name { get; set; }
        public LastName LastName { get; set; }
    }

So if you will create a record following this model, then you will get the desired json. It has nothing to do with Avro.

AlbertoMonteiro commented 8 months ago

Yeah, I knew that I can create other types to do this, actually it isn't a viable solution for my need.

Thanks for the attention!