I am looking to see how to set the json serializor converter settings when you call _jsRuntime.InvokeAsync method. The method it self doesn't take in any json serialization settings. I believe you would need to set the settings for the project. So far I have not been able to find a way to achieve that.
My Converter:
public class VectorConverter : JsonConverter<System.Numerics.Vector3>
{
public override System.Numerics.Vector3 Read(ref Utf8JsonReader reader,
Type typeToConvert, JsonSerializerOptions options)
{
if(reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException();
}
System.Numerics.Vector3 result = new System.Numerics.Vector3();
while (reader.Read())
{
if(reader.TokenType == JsonTokenType.EndObject)
{
return result;
}
if(reader.TokenType != JsonTokenType.PropertyName)
{
throw new JsonException();
}
switch(reader.GetString())
{
case "x":
result.X = (float)reader.GetDouble();
break;
case "y":
result.Y = (float)reader.GetDouble();
break;
case "z":
result.Z = (float)reader.GetDouble();
break;
}
}
throw new JsonException();
}
public override void Write(Utf8JsonWriter writer,
System.Numerics.Vector3 value, JsonSerializerOptions options)
{
writer.WriteNumber("x", value.X);
writer.WriteNumber("y", value.Y);
writer.WriteNumber("z", value.Z);
}
}