AdrianStrugala / AvroConvert

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

Provide a way to serialize DateTime using millis or micros #153

Open robertcoltheart opened 3 months ago

robertcoltheart commented 3 months ago

Describe the solution you'd like We have a need to serialize DateTime values as a millis logical type, not micros, which is the default. There isn't a way to select a different logical type that I can see.

Describe implementation idea Perhaps a LogicalTypeAttribute with a way to select a specific logical type for a property would be the way to go? I'm not sure what other mechanism could solve this, though you may perhaps have some ideas.

AdrianStrugala commented 3 months ago

Hey, Maybe it would make sense to create a fully flexible AvroTypeAttribute. I will check out the options. Best, Adrian

AdrianStrugala commented 2 months ago

Hello @robertcoltheart

Thank you for your contribution. The new feature is available from v.3.4.7 of AvroConvert. Example usage:

    public class TypeAttributeClass
    {
        [AvroType(AvroTypeRepresentation.Double)]
        public int Int;

        [AvroType(AvroTypeRepresentation.TimestampMilliseconds)]
        public DateTime DateTime;
    }

Regards, Adrian