I am getting NullRef exception when calling below.
System.NullReferenceException occurred
Message: Exception thrown: ‘System.NullReferenceException’ in ServiceStack.Text.dll
Additional information: Object reference not set to an instance of an object.
Here’s some info around serializing Struct values, i.e ServiceStack serializes a struct using their ToString() and tries to deserialize it with a single string constructor or a static Parse(string) function.
If it’s your own Struct you can customize deserialization by implementing a static ParseJson() method. If it can be treated as a reference type, i.e. only has public serializable properties you can tell ServiceStack to treat it as a reference type with:
JsConfig<Rectangle>.TreatValueAsRefType = true;
Otherwise you’ll need to customize the serialization by providing custom:
JsConfig<Rectangle>.SerializeFn = r => $$"{r.X},{r.Y},{r.Width},{r.Height}";
JsConfig<Rectangle>.DeSerializeFn = s => {
var parts = s.Split(',');
return new Rectangle(
int.Parse(parts[0]),
int.Parse(parts[1]),
int.Parse(parts[2]),
int.Parse(parts[3]));
};