SharpYaml icon indicating copy to clipboard operation
SharpYaml copied to clipboard

Ignore unmapped properties in YAML

Open Cinchoo opened this issue 2 years ago • 2 comments

Given a YAML file that contains more information than the object deserializing it, the current implementation will throw an exception because there is not a corresponding object property for all properties in the YAML file.

Cinchoo avatar Jul 31 '21 22:07 Cinchoo

new SharpYaml.Serialization.SerializerSettings()
{
    IgnoreUnmatchedProperties = true
}

doesn't this help?

krisrok avatar Dec 16 '21 14:12 krisrok

new SharpYaml.Serialization.SerializerSettings()
{
    IgnoreUnmatchedProperties = true
}

doesn't this help?

I am seeing the same issue. Setting the property IgnoreUnmatchedProperties to true only works if the the property's value is a primitive type. For any property that is set to a map or list will throw an exception.

nickcampau avatar Jun 02 '22 17:06 nickcampau

Seeing the same. Getting Expected 'Scalar', got 'MappingStart' error when setting IgnoreUnmatchedProperties to true and the yaml having an unmatched property that's a map.

Benna96 avatar Feb 15 '23 02:02 Benna96

Same problem...

@xoofx can you guide me a little? I can try to create a PR.

I understand that the problem has to be around here:

https://github.com/xoofx/SharpYaml/blob/f7960e28f9461d4e60bcd04f622f413548937dc1/src/SharpYaml/Serialization/Serializers/ObjectSerializer.cs#L197

https://github.com/xoofx/SharpYaml/blob/f7960e28f9461d4e60bcd04f622f413548937dc1/src/SharpYaml/Serialization/Serializers/ObjectSerializer.cs#L234

bdovaz avatar Feb 12 '24 15:02 bdovaz