xvlv
Easiest way to serialize System.Numerics.Vector3 using System.Text.Json (.NET 8)
I'm writing a 3D level editor in .NET and OpenGL and need level data to be stored as human-readable text, so I'm using System.Text.Json. Since
Vector3
exposes its data as fields instead of properties, it always gets serialized as {}
:
I wrote this custom converter that writes the value as "1,2,3"
:
I'm curious if this is the recommended approach or is there's an easier way to do the same thing (besides using Newtonsoft). Has anyone else implemented anything similar? Wanted to ask here before I implement custom converters for Vector2
, Quaternion
, etc.3 replies