Bundle: redb-route / redb.Route.DataFormats.Yaml (redb.Route.DataFormats.Yaml.txt), 5 files Snapshot: development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt ==== Path: redb-route/redb.Route.DataFormats.Yaml/README.md Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.DataFormats.Yaml/README.md ---- # redb.Route.DataFormats.Yaml > Documentation and articles: YAML as a redb.Route data format, on [YamlDotNet](https://github.com/aaubry/YamlDotNet). ```csharp .UnmarshalYaml() // string / byte[] / Stream → POCO .UnmarshalYaml() // → Dictionary / List tree .MarshalYaml(o => o.NamingConvention = PascalCaseNamingConvention.Instance) context.AddYamlDataFormat(); // then Marshal("application/yaml"), Unmarshal("application/yaml"), // and ContentType-driven Unmarshal() for application/x-yaml, text/yaml ``` Options: `NamingConvention` (camelCase by default, like the JSON codec), `IgnoreUnmatchedProperties` (`true`). Malformed YAML fails with an error naming the format. Path: redb-route/redb.Route.DataFormats.Yaml/YamlDataFormat.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.DataFormats.Yaml/YamlDataFormat.cs ---- using System.Collections; using System.Text; using redb.Route.Abstractions; using YamlDotNet.Core; using YamlDotNet.Serialization; namespace redb.Route.DataFormats.Yaml; /// /// YAML (YamlDotNet). Marshals any object; unmarshals to a POCO, or to a /// dynamic tree (Dictionary<string, object?> / List<object?> / scalars) when the target /// is object. Errors name the format. /// public sealed class YamlDataFormat : IMessageSerializer { /// Content type the format is registered under. public const string DefaultContentType = "application/yaml"; /// The name the format answers to in markup, <marshal format="yaml"/>, as Apache Camel names it; AddYamlDataFormat() registers it. public const string Name = "yaml"; private readonly YamlDataFormatOptions _options; private readonly ISerializer _serializer; private readonly IDeserializer _deserializer; /// Creates the format with the given options (defaults when null). public YamlDataFormat(YamlDataFormatOptions? options = null) { _options = options ?? new YamlDataFormatOptions(); _serializer = new SerializerBuilder().WithNamingConvention(_options.NamingConvention).Build(); var builder = new DeserializerBuilder().WithNamingConvention(_options.NamingConvention); if (_options.IgnoreUnmatchedProperties) builder = builder.IgnoreUnmatchedProperties(); _deserializer = builder.Build(); } /// The options in effect. public YamlDataFormatOptions Options => _options; /// public string ContentType => DefaultContentType; /// public IReadOnlyCollection MediaTypes => [DefaultContentType, "application/x-yaml", "text/yaml", "text/x-yaml"]; /// public byte[] Serialize(T value) { switch (value) { case null: return []; case byte[] bytes: return bytes; case string text: return Encoding.UTF8.GetBytes(text); } try { return Encoding.UTF8.GetBytes(_serializer.Serialize(value)); } catch (YamlException ex) { throw new InvalidOperationException($"YAML data format: cannot marshal {value.GetType().Name} ({ex.Message}).", ex); } } /// public T? Deserialize(byte[] data) => (T?)Deserialize(data, typeof(T)); /// public object? Deserialize(byte[] data, Type type) { ArgumentNullException.ThrowIfNull(data); ArgumentNullException.ThrowIfNull(type); var text = Encoding.UTF8.GetString(data); if (type == typeof(string)) return text; try { return type == typeof(object) ? Normalize(_deserializer.Deserialize(text)) : _deserializer.Deserialize(text, type); } catch (YamlException ex) { throw new InvalidOperationException($"YAML data format: the body is not valid YAML for {type.Name} ({ex.Message}).", ex); } } /// YamlDotNet's dynamic tree uses Dictionary<object, object>; expressions and templates want string keys. private static object? Normalize(object? node) => node switch { IDictionary dictionary => NormalizeMap(dictionary), string s => s, IEnumerable list => list.Cast().Select(Normalize).ToList(), _ => node, }; private static Dictionary NormalizeMap(IDictionary dictionary) { var result = new Dictionary(StringComparer.Ordinal); foreach (DictionaryEntry entry in dictionary) result[entry.Key?.ToString() ?? string.Empty] = Normalize(entry.Value); return result; } } Path: redb-route/redb.Route.DataFormats.Yaml/YamlDataFormatOptions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.DataFormats.Yaml/YamlDataFormatOptions.cs ---- using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; namespace redb.Route.DataFormats.Yaml; /// Options of one instance. public sealed class YamlDataFormatOptions { /// Property naming in the document. Default camelCase (the same choice as the JSON codec). public INamingConvention NamingConvention { get; set; } = CamelCaseNamingConvention.Instance; /// Ignore document keys that have no matching property on unmarshal. Default true. public bool IgnoreUnmatchedProperties { get; set; } = true; } Path: redb-route/redb.Route.DataFormats.Yaml/YamlRouteDefinitionExtensions.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.DataFormats.Yaml/YamlRouteDefinitionExtensions.cs ---- using redb.Route.Abstractions; using redb.Route.Extensions; namespace redb.Route.DataFormats.Yaml; /// DSL and registration sugar for . public static class YamlRouteDefinitionExtensions { /// Marshals the body to YAML. public static IRouteDefinition MarshalYaml(this IRouteDefinition route, Action? configure = null) => route.Marshal(new YamlDataFormat(Build(configure))); /// Unmarshals YAML to (object gives a string-keyed dictionary / list tree). public static IRouteDefinition UnmarshalYaml(this IRouteDefinition route, Action? configure = null) => route.Unmarshal(new YamlDataFormat(Build(configure))); /// Registers YAML as application/yaml (and its aliases) on the context. public static IRouteContext AddYamlDataFormat(this IRouteContext context, Action? configure = null) => context.AddDataFormat(new YamlDataFormat(Build(configure)), YamlDataFormat.Name); /// DI form of . public static RedbRouteBuilder AddYamlDataFormat(this RedbRouteBuilder builder, Action? configure = null) => builder.AddDataFormat(new YamlDataFormat(Build(configure)), YamlDataFormat.Name); private static YamlDataFormatOptions Build(Action? configure) { var options = new YamlDataFormatOptions(); configure?.Invoke(options); return options; } } Path: redb-route/redb.Route.DataFormats.Yaml/redb.Route.DataFormats.Yaml.csproj Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.DataFormats.Yaml/redb.Route.DataFormats.Yaml.csproj ---- redb.Route.DataFormats.Yaml YAML data format for redb.Route (YamlDotNet): Marshal/Unmarshal of POCOs and dynamic documents; registered as application/yaml. esb;messaging;yaml;dataformat;redb README.md