I need to serialize a class object whose field is a custom data type matrix, like:
internal class MyClass
{
private readonly MyMatrix[,] myField;
public MyField { get => myField; }
}
I am using json serialization code from here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/how-to?pivots=dotnet-7-0
public static bool Save(MyClass o, string fileName)
{
_ = new JsonSerializerOptions { IncludeFields = true };
try
{
byte[] jsonString = JsonSerializer.SerializeToUtf8Bytes(o);
File.WriteAllBytes(fileName, jsonString);
return true;
}
catch (Exception e)
{
Console.WriteLine("Exception in serialization: " + e.Message);
return false;
}
}
When trying to serialize an object of this class, I get an exception like this: (https://i.stack.imgur.com/lhbbE.png)
I already understood that json supports a limited list of data types, but what should I do to serialize and then deserialize such an object?