OneYaml.Compat.YamlDotNet is a subset of YamlDotNet’s API on top of OneYaml: the serializer builders and the representation model, tested against YamlDotNet 18.1.0. Swap the package and the namespaces, and the builder calls stay.
dotnet remove package YamlDotNet dotnet add package OneYaml.Compat.YamlDotNet --version 1.2.1
using OneYaml.Compat.YamlDotNet.Serialization; // was: YamlDotNet.Serialization using OneYaml.Compat.YamlDotNet.Serialization.NamingConventions; // was: YamlDotNet.Serialization.NamingConventions // The same builders and calls as YamlDotNet. IDeserializer deserializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .IgnoreUnmatchedProperties() .Build(); var service = deserializer.Deserialize<Service>("name: web\nreplicas: 2\nlegacy: true\n"); Console.WriteLine($"{service.Name} x{service.Replicas}"); ISerializer serializer = new SerializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build(); Console.Write(serializer.Serialize(service)); class Service { public string Name { get; set; } = ""; public int Replicas { get; set; } }
web x2 name: web replicas: 2
Good to know
- Not covered: static contexts, type inspectors, node deserializers, the scanner and comment events. The package page lists what is covered and every difference.
- The compatibility package is a bridge. For new code,
YamlSerializerandYamlDocumentin theOneYamlpackage read YAML 1.2, keep comments when you edit, and support native AOT. - From SharpYaml, the bridge is
OneYaml.Compat.SharpYaml(package page, migration guide).
What to check after the swap, and how to move to the OneYaml API itself, are in Migrating from YamlDotNet.
A longer guide: Replacing YamlDotNet.