The problem was to serialize/deserialize a class with Color
from System.Drawing.Color
with System.Text.Json
.
public class Test
{
public Color Farbe { get; set; }
public IEnumerable<Color> Farben { get; set; }
}
Serialization
File.WriteAllText("data.json", JsonSerializer.Serialize(test));
without any converters the serialized json file looks like this:
{
"Farbe": {
"R": 255,
"G": 0,
"B": 0,
"A": 255,
"...": "...",
"Name":" Red"
},
"Farben": [
{
"R":255,
"G":0,
"B":0,
"A":255,
"...": "...",
"Name":"Red"
},
{
"R":0,
"G":128,
"B":0,
"A":255,
"...": "...",
"Name":"Green"
}
]
}
Deserialisation is not possible. The result will be empty:
Test test2 = JsonSerializer.Deserialize<Test>(File.ReadAllText("data.json"));
Console.WriteLine($"{test2.Farbe.R}:{test2.Farbe.G}:{test2.Farbe.B}");
Console.WriteLine(string.Join(',', test2.Farben));
Result
0:0:0
Color [Empty],Color [Empty],Color [Empty]