❔ Cannot deserialize System.Drawing.Color from JSON
It seems like the System.Text.Json library is not able to deserialize a Color from a JSON string it serialized before.
Code I used for testing:
Code I used for testing:


Compile: 549.845ms | Execution: 48.130ms | React with ❌ to remove this embed.
toJsonColorColor [A=255, R=255, G=15, B=54]"FieldName" : "R, G, B"System.Text.Json.JsonSerializer.Serialize((1, 2, 3, 4)){}using System.Drawing;
using System.Text.Json;
public class ColorSerializer
{
struct col
{
public byte R{get;set;}
public byte G{get;set;}
public byte B{get;set;}
public byte A{get;set;}
}
public static string Serialize(Color color)
{
var foo = new col{R=color.R,G=color.G,B=color.B,A=color.A};
return JsonSerializer.Serialize(foo);
}
public static Color Deserialize(string str)
{
var foo = JsonSerializer.Deserialize<col>(str);
return Color.FromArgb(foo.A, foo.R, foo.G, foo.B);
}
}
Color toJson = Color.FromArgb(0xFF, 0xF, 0x36);
string inJson = ColorSerializer.Serialize(toJson);
Color fromJson = ColorSerializer.Deserialize(inJson);
Console.WriteLine(fromJson);public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options)
{
writer.WriteStringValue($"{value.R}, {value.G}, {value.B}");
}