Skip to content

YamlDotNet is a .NET library for YAML

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE-libyaml
Notifications You must be signed in to change notification settings

sbhenderson/YamlDotNet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YamlDotNet

Travis Appveyor NuGet
Travis CI Build status NuGet

YamlDotNet is a .NET library for YAML. YamlDotNet provides low level parsing and emitting of YAML as well as a high level object model similar to XmlDocument. A serialization library is also included that allows to read and write objects from and to YAML streams.

Currently, YamlDotNet supports version 1.1 of the YAML specification.

What is YAML?

YAML, which stands for "YAML Ain't Markup Language", is described as "a human friendly data serialization standard for all programming languages". Like XML, it allows to represent about any kind of data in a portable, platform-independent format. Unlike XML, it is "human friendly", which means that it is easy for a human to read or produce a valid YAML document.

The YamlDotNet library

The library has now been successfully used in multiple projects and is considered fairly stable.

More information

More information can be found in the project's wiki.

Installing

Just install the YamlDotNet NuGet package:

PM> Install-Package YamlDotNet

If you need signed assemblies, install the YamlDotNet.Signed NuGet package instead:

PM> Install-Package YamlDotNet.Signed

If you do not want to use NuGet, you can download binaries here.

YamlDotNet is also available on the Unity Asset Store.

Contributing

Please read CONTRIBUTING.md for guidelines.

Changelog

Version 5.4.0

New features:

  • Enable serialization of public fields.
    YamlDotNet will now also serialize public fields. This feature is enabled by default, but it can be disabled by calling IgnoreFields() no the SerializerBuilder or DeserializerBuilder.

Version 5.3.1

New features:

  • Produce a detailed error message when too much recursion is detected during serialization.

Version 5.3.0

New features:

  • Add support for supplying custom IObjectGraphTraversalStrategy implementations.
  • Add abstract WithTagMapping() method to the base serializer / deserializer builder.

Bug fixes:

  • Use BenchmarkDotNet and Compile YamlDotNet with Optimize option in Release-* configurations

Version 5.2.1

Bug fixes:

  • Fix roundtripping of tags on sequences (#347)

Version 5.2.0

Improvements:

Version 5.1.0

Improvements:

  • Add interfaces for serializer and deserializer (fixes #350).

Fixes:

  • Fixed issue #348 that caused the assembly to have version 0.0.0.0.

Version 5.0.0

/!\ This release fixes a security issue - CVE-2018-1000210. It is strongly recommended to upgrade, mainly if you are parsing documents from sources that you do not trust.

Many thanks to Kurt Boberg, from the DocuSign Application Security Team, who identified this issue and provided feedback on mitigation strategies.

  • Remove the legacy backwards-compatibe syntax that enabled to create Serializer and Deserializer directly then changing their configutation.
    In most cases, the calls to the constructors should be replaced by instantiations of SerializerBuilder and DeserializerBuilder. These can be configured at will, then used to create instances of (De)serializer. It is still possible to use the default constructors, if no configuration is needed.

  • Drop support for specifying arbitrary type names in tags.
    Support for automatically resolving a fully qualified type name from a tag has been discontinued. That feature was poorly designed and not standard.
    During deserialization, each tag mapping must be explicitly registered. During serialization, when using the EnsureRoundtrip method, it is necessary to register tag mappings for each type that will require a tag, that is, any type that is used as the value of a property with a different declared type.

  • Fix bug where deserialized values were not being converted to the destination type.

    var sut = new DeserializerBuilder()
        .WithTagMapping("!dbl", typeof(DoublyConverted))
        .Build();
    
    // The scalar "hello" will first be converted to DoublyConverted
    // then that value will be converted to int.
    var result = sut.Deserialize<int>("!dbl hello");
    
    Assert.Equal(5, result);

Version 4.3.2

  • Fix issue #308: Comment on line start parsed as inline
  • Fix bug where TypeConverter was being ignored on all platforms except .NET 3.5
  • Remove serialization support from exceptions.
  • This is actually a breaking change, but I don't think that anyone relies on this.

Version 4.3.1

  • Avoid definition of SerializationException (and some other types) on NET Standard

Version 4.3.0

  • Add support for (de)serialization of System.Type

Version 4.2.4

  • Refactored the project and solution so that they load and build cleanly in VS2017.
  • Reviewed the target platforms.
    • The currently supported platforms are now:
      • .NET Framework 4.5
      • .NET Framework 3.5
      • .NET Framework 2.0 (experimental)
      • .NET Standard 1.3
      • Unity Subset v3.5
    • The following platforms are no longer supported:
      • Profile259 (please upgrade to netstandard)

Version 4.2.3

Bug fixes:

  • Fix nested reference merging.
  • Don't force coercion of dictionary keys to string.
  • Fix public static method determining in PORTABLE mode.

Version 4.2.2

Bug fixes:

  • Actualy cache in CachedTypeInspector.

Version 4.2.1

Bug fixes:

  • Fix parser behavior when skipComments == false
    In most cases, the parser failed to parse after encountering a comment.

Version 4.2.0

New features

  • Support for .NET Core (netstandard1.3).
    The project files have been converted to the new format, which means that older versions of Visual Studio may be unable to load them.

Development-related changes

  • YamlDotNet now uses Cake to define the build script. Previously, custom powershell scripts were used.

  • Docker images are now available with everything that is required to build YamlDotNet, both locally, and on Travis. This is mostly useful for people wanting to develop on Linux, as it can be tricky to install the correct versions of the dependencies.

  • Code samples are now part of the solution
    They are specified as tests, and the samples section of the wiki is generated from their source code and their output.

Version 4.1.0

New features

  • 32bits Unicode code points in escape sequences and url-encoded tags are now properly handled.

  • Anchors can now be redefined in a document.
    This is to conform to the 1.1 spec as well as the 1.2 spec:

    3.2.2.2. Anchors and Aliases

    When composing a representation graph from serialized events, an alias node refers to the most recent node in the serialization having the specified anchor. Therefore, anchors need not be unique within a serialization.

  • Added support for tag mappings on the serializer.
    Use SerializerBuilder.WithTagMapping() to register a new tag mapping on the serializer.

  • Allow to unregister components from the SerializerBuilder and DeserializerBuilder.
    Use the Without... methods on SerializerBuilder and DeserializerBuilder for that.

  • New DateTimeConverter

    • It accepts DateTimeKind.Utc and Standard Date and Time Format Strings of "G" as its default parameters, if they are omitted.
    • For deserialisation, it accepts as many number of formats as we want. If a value doesn't match against provided formats, it will return FormatException. Please refer to my whole test cases.
    • For serialisation, it only considers the first format in the format list.
  • Improve the (de)serializer builders so that it is possible to wrap existing component registrations.

  • Added the ApplyNamingConventions property to YamlMemberAttribute.
    When this property is true, naming conventions are not applied to the associated member. This solves issue 228.

Bug fixes

Other

  • The samples have been added to the project as a new unit test project, to ensure that they stay up-to-date with the code. In the future, a documentation page will be generated from the samples, that will show the sample, its documentation and respective output.

Version 4.0.0

This a major release that introduces a few breaking changes.

Breaking changes

  • The constructors of Serializer and Deserializer are now obsolete
    Except for the parameterless versions. The SerializerBuilder and DeserializerBuilder classes should now be used to configure and create instances of the (de)serializer.

  • Replaced the IYamlSerializable interface with IYamlConvertible
    The IYamlSerializable is now obsolete, but will be kept until the next major release.

  • Removed EventReader
    EventReader was a wrapper over IParser that offered some abstractions for parsing, but also had some design flaws. It has been replaced by extension methods for IParser. The extension methods provide the same functionality, and allow to always use the same type to represent the parser.

  • Dropped support for YamlAliasAttribute
    This class has been obsolete for many releases, and it was time to let it go.

New features

  • SerializerBuilder and DeserializerBuilder
    This is an important change that adds "builders" that can be used to configure the Serializer and Deserializer through a fluent syntax. The main objective of this is to allow more control over the composition of services performed by these two classes. This means that every aspect of the composition should be extensible / overridable. Things like injecting a custom TypeInspector or replacing the the default ArrayNodeDeserializer with an alternative implementation become possible and easy.
    In order to avoid breaking existing code, the constructors of Serializer and Deserializer have been kept but marked as obsolete. In a future release they will be discarded.

  • Added the IYamlConvertible interface
    This new interface differs in that its methods receive a delegate that can be used to reuse the current serializer or deserializer.

  • Improved the usability of YamlDocument
    and other RepresentationModel classes:

    • Added conversion operators and indexers for easier parsing and construction of YamlNodes.
    • YamlMappingNode, YamlSequenceNode and YamlScalarNode now implement IYamlConvertible, which means that these types can appear in the middle of an object that is being serialized or deserialized, and produce the expected result.
  • Added support for alternative Boolean values

    • True: true, y, yes, on
    • False: false, n, no, off.

Bug fixes

Version 3.9.0

New features:

  • Add YamlVisitorBase as an improved replacement for YamlVisitor
    • YamlVisitor is now obsolete, and will be removed in a future release.
  • Ensure compatibility with AOT compilation, for platforms that do not allow dynamic code generation, such as IOS or PS4.
  • Add Yaml attribute overrides feature, similar to XML Serializer attribute overrides behavior.
  • Add a YamlNodeType enumeration property to nodes.

Bug fixes:

  • Fix #166 - Guid conversion to JSON is unquoted.
  • Ignore enum value case during deserialization.
  • Improve newline handling
    • In some cases, consecutive newlines were incorrectly parsed or emitted.
  • Fix #177 - double.MaxValue serialization.
  • Register custom type converters with higher precedence than the built-in converters.

Version 3.8.0

New features:

  • Add support for different scalar integer bases.
    Addresses issue #113. Adds basic support for deserializing scalar integers written in binary, octal, decimal, hex, and base 60, as allowed in the YAML specification; see http://yaml.org/type/int.html. Adds unit tests for each of these bases as well.
  • Add dnx compatibility to the NuGet packages.
  • Do not throw exception if a tag does not contain a valid type name.

Fixes and improvements:

  • Cache type metadata.
  • Fix wrong type when deserializing UInt16.
  • Fix handling of special float values, such as NaN, PositiveInfinity and NegativeInfinity.
  • Properly quote empty strings.
  • Properly handle non-Unicode encodings when emitting scalars.

Version 3.7.0

This is a minor update that simply adds an overload of YamlStream.Load to be able to specify the EventReader.

Version 3.6.1

Bug fixes:

  • Bug in the GetPublicMethods implementation for portable.

Version 3.6.0

New features:

  • Ability to opt out of anchor assignment during YamlStream.Save().
  • Allow the style of scalar properties to be specified through the YamlMember attribute.
  • Add solution configuration to target "Unity 3.5 .net Subset Base Class Libraries".

Bug fixes:

  • Do not compare nodes by value while assigning anchors. It is the responsibility of the user to use the same reference if they want an alias.
  • Fixed #121: Finding properties in parent interfaces

Version 3.5.1

Fix bug:

  • Scalars returned by the scanner do not have their Start and End properties set.

Version 3.5.0

  • Add native support of System.Guid serialization.
  • Add properties to YamlMemberAttribute:
    • Order: specifies the order of the members when they are serialized.
    • Alias: instructs the deserializer to use a different field name for serialization.
  • The YamlAliasAttribute is now obsolete. New code should use YamlMemberAttribute instead.
  • Throw proper exceptions, with correct marks, when deserialization of a node fails.

Version 3.4.0

Changes and fixes on the Scanner to make it more usable:

  • Report the location of comments correctly, when the scanner is created with "skipComments = false"
  • In case of syntax error, do not report an empty range and skip to the next token.
  • Make the scanner and related types serializable, so that the state of the scanner can be captured and then restored later (assuming that the TextReader is also serializable).

Version 3.3.1

This release adds a signed package and portable versions of the library.

Version 3.3.0

  • Make types in YamlDotNet.RepresentationModel serializable.

Version 3.2.1

  • Fix AnchorNotFoundException when another exception occurs during deserialization.

Version 3.2.0

This release adds merge key support: http://yaml.org/type/merge.html

Example from BackreferencesAreMergedWithMappings unit test:

var reader = new EventReader(new MergingParser(new Parser(stream)));
var result = Deserializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(parser);

Version 3.1.1

This is a bugfix release that fixes issue #90.

Version 3.1.0

  • Add a parameter to the deserializer to ignore unmapped properties in YAML.

Version 3.0.0

  • Fix issue #26: Use the actual type of the objects instead of the statically detected one.
  • Merged the Core, Converters and RepresentationModel assemblies. The NuGet packages YamlDotNet.Core and YamlDotNet.RepresentationModel are now a single package, named YamlDotNet.
  • Removed YamlDotNet.Configuration and YamlDotNet.Converters.
  • Line numbers in error messages now start at one.
  • TypeConverter is now used to cast list items.
  • Various code improvements.
  • More and better unit tests.

Version 2.2.0

TODO

Version 2.1.0

TODO

Version 2.0.0

  • YamlSerializer has been replaced by the Deserializer class. It offer the same functionality of YamlSerializer but is easier to maintain and extend.

    • Breaking change: DeserializationOverrides is no longer supported. If you need this, please file a bug and we will analyze it.
    • Breaking change: IDeserializationContext is no longer supported. If you need this, please file a bug and we will analyze it.
    • Tag mappings are registered directly on the Deserializer using RegisterTagMapping()
    • ObjectFactory is specified in the constructor, if required.
  • Bug fixes to the Serializer:

    • Fix bug when serializing lists with nulls inside. e9019d5f224f266e88d9882502f83f0c6865ec24
  • Adds a YAML editor add-in for Visual Studio 2012. Available on the Visual Studio Gallery.

About

YamlDotNet is a .NET library for YAML

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE-libyaml

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.1%
  • Other 0.9%