Serialization
Custom converters
Own the read/write of a type with Avm1Converter<T>: how to attach it, resolution precedence, and factories.
Subclass Avm1Converter<T> to own the read/write of a type:
public sealed class CoordConverter : Avm1Converter<Coord>
{
public override Coord Read(Avm1Value v, Avm1SerializerOptions o)
{
var parts = v.AsString.Split(',');
return new Coord(int.Parse(parts[0]), int.Parse(parts[1]));
}
public override Avm1Value Write(Coord c, Avm1SerializerOptions o) => new Avm1String($"{c.X},{c.Y}");
}Attach it to a type or a member, or register it on the options.
Resolution order
Resolution order (highest first):
[Avm1Converter]on the member.- a converter in
Options.Converters(first whoseCanConvertmatches;Avm1ConverterFactoryinstances are asked to create one). [Avm1Converter]on the type.- the built-in converter.
A type handled by a custom converter is opaque: it has no configurable properties and is
read/written wholly by the converter — the same rule System.Text.Json uses.