systemerror Actually, I asked a stupid question.
I'm just trying to convert a custom data structure to a string, so it's definitely not a Godot problem. But as I said, I'm new to both Godot and C#, so after searching for half an hour and not finding anything, I came here for help.
Usually most programming languages expose virtual methods for conversion if they have a Convert library, so then I searched for virtual methods for JsonSerialization Convert and implemented it myself.
public class Vector2IJsonConverter : JsonConverter<Vector2I>
{
public override Vector2I Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
return (Vector2I)GD.StrToVar(reader.GetString()!);
}
public override void Write(
Utf8JsonWriter writer,
Vector2I vector2iValue,
JsonSerializerOptions options)
{
writer.WriteStringValue(GD.VarToStr(vector2iValue));
}
}
Everything worked as expected now.