Well although the customizability options are limited at the moment, there are a few options.
If you could return a string value you can use struct's to completely customize a types JSON output, e.g:
public struct PointStruct
{
public double X { get; set; }
public double Y { get; set; }
public override string ToString()
{
return "(" + X + "," + Y + ")";
}
public static PointStruct Parse(string json)
{
var points = json.FromJson<int[]>();
return new PointStruct { X = points[0], Y = points[1] };
}
}
[Test]
public void Can_serialize_GeoJSON_point_with_structs()
{
Assert.That(new PointStruct{ X = 1, Y = 2}.ToJson(), Is.EqualTo("\"(1,2)\""));
}
Although since this needs to be in quotes then it may not be the best option.
Though in this case, for the customizable array output as above you can still use a custom class if it's IEnumerable since it will be treated and serialized to a JSON array, e.g:
public class PointArray : IEnumerable
{
double[] points = new double[2];
public double X
{
get
{
return points[0];
}
set
{
points[0] = value;
}
}
public double Y
{
get
{
return points[1];
}
set
{
points[1] = value;
}
}
public IEnumerator GetEnumerator()
{
foreach (var point in points)
yield return point;
}
}
[Test]
public void Can_serialize_GeoJSON_point_with_PointArray()
{
Assert.That(new PointArray{ X = 1, Y = 2 }.ToJson(), Is.EqualTo("[1,2]"));
}