Serialize Struct with private fields
Hello,
I was wondering if this project supports the Instant data type from the NodaTime library? I tried to generate a schema for a simple record that had an Instant property but when I went to serialize, I got an error stating that 'Instance property 'MinValue' is not defined for type 'NodaTime.Instant' (Parameter 'propertyName')'. It looks like the instant could not be serialized properly as the schema did not know about this MinValue property. Is there any way to support this data type? I am considering using this library and trying to prototype something with it.
The type I try to serialize:
public class Error
{
public int Id { get; set; }
public string AppName { get; set; }
public Instant Date { get; set; }
}
The app code that throws an error:
Error appError = new Error
{
AppName = "MyApplication",
Id = 123,
Date = SystemClock.Instance.GetCurrentInstant()
};
string avroSchema = AvroConvert.GenerateSchema(typeof(Error));
var serialized = AvroConvert.SerializeHeadless(appError, avroSchema); // Error here
Hello,
Thank you for creating the issue. I will take a look at this.
Regards, Adrian
Hello,
The issue seems to be more complex than expected. Instant is a struct holding its value as a private field. Additionally contains a couple of helper methods and other private fields.
My proposition as a workaround is to serialize the date to a string:
SystemClock.Instance.GetCurrentInstant().ToString()
I will try to figure out a fix, but it may take some time.
Regards, Adrian
Hello,
The issue seems to be more complex than expected. Instant is a struct holding its value as a private field. Additionally contains a couple of helper methods and other private fields.
My proposition as a workaround is to serialize the date to a string:
SystemClock.Instance.GetCurrentInstant().ToString()I will try to figure out a fix, but it may take some time.
Regards, Adrian
Yeah this is what I have done and actually may work better for what Ill need! Thanks for the response.
At the moment there is no plan for direct support of private fields serialization