4

Does YamlDotNet support deserializing a document where there are fields in the document that do not map to a field in the resulting object? For example:

Given a type:

public class Foo {
    public string AField { get; set; }
}

If I use YamlDotNet's Deserialize on the following document it generates an exception:

Foo:
  AField: This is a test
  NotFoundField: This field is not supported yet

Looking at the YAML spec it should be allowable that the non-matching field should be ignored. Looking at the YamlDotNet code, it looks like it is assumed that the all fields in the document will map into the resulting object.

Is there an existing way to make the parsing "permissive" or am I going to need to modify YamDotNet to allow this?

cregbrad
  • 100
  • 1
  • 5

1 Answers1

5

The current behavior of the deserializer is to assume that each key maps to a property. It should not be difficult to implement the behavior that you need, though.

There is now a flag to configure this behavior: https://github.com/aaubry/YamlDotNet/pull/88

Antoine Aubry
  • 12,203
  • 10
  • 45
  • 74