Skip to content

Commit

Permalink
Merge pull request #22 from sia-digital/feat/yaml_deserialize_ignore_…
Browse files Browse the repository at this point in the history
…unmatched_props

Allow YAML Deserialize Extension to ignore unmatched properties
  • Loading branch information
redbit86k authored Dec 19, 2023
2 parents 6a4f2ee + 647c742 commit 367913f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class SerializationExtensions

private static readonly IDeserializer _deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.WithDuplicateKeyChecking()
.WithTypeConverter(new ValueObjectYamlTypeConverter())
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public void CanSerializeAndDeserializeYaml()
{
var sample = new Sample { HealthCheckTag = HealthCheckTag.Liveness, Name = "test" };
var serialized = sample.Serialize(SerializationMethod.Yaml);
var withSchema = "$schema: bla.json" + Environment.NewLine + serialized;
var deserialized = serialized.Deserialize<Sample>(SerializationMethod.Yaml);
var deserializedWithSchema = withSchema.Deserialize<Sample>(SerializationMethod.Yaml);

deserialized.Should().BeEquivalentTo(sample);
deserializedWithSchema.Should().BeEquivalentTo(sample);

var obj = serialized.Deserialize(typeof(Sample), SerializationMethod.Yaml);
obj.Should().BeOfType<Sample>();
Expand Down

0 comments on commit 367913f

Please sign in to comment.