YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

WritablePropertiesTypeInspector does not respect the `Alias` from `YamlConverterAttribute`

Open TheBigNeo opened this issue 3 months ago • 4 comments

Describe the bug The WritablePropertiesTypeInspector does not take into account the Alias property of the YamlConverterAttribute. It is missing in the constructor of the ReflectionPropertyDescriptor.

If I create a PR for this, would it be accepted and merged soon?

TheBigNeo avatar Sep 15 '25 06:09 TheBigNeo

Ahh, now I see it. I have to chain the TypeInspectors.

public static DeserializerBuilder CreateDeserializerBuilder()
{
    WritablePropertiesTypeInspector writablePropertiesInspector                  = new WritablePropertiesTypeInspector(new DynamicTypeResolver());
    YamlAttributesTypeInspector     writablePropertiesInspectorWithYamlAttribute = new YamlAttributesTypeInspector(writablePropertiesInspector);
    DeserializerBuilder             deserializerBuilder                          = new DeserializerBuilder();

    deserializerBuilder.WithoutTypeInspector<YamlAttributesTypeInspector>();
    deserializerBuilder.WithTypeInspector(_ => writablePropertiesInspectorWithYamlAttribute);

    return deserializerBuilder;
}

Is that correct, or am I making a mistake here?

TheBigNeo avatar Sep 15 '25 07:09 TheBigNeo

You dont chain the type inspector. It takes in a type resolver. And if I remember right, the alias is taken into account higher up in the call stack.

EdwardCooke avatar Sep 16 '25 19:09 EdwardCooke

Ok, I take that back. You do bring in the other type inspectors. Though I think that is done with the WithTypeInspector. And you don't want to remove the YamlAttributesTypeInspector, that's where it determines the alias of the property/field. Should be higher up in the call chain than the WritablePropertiesInspector.

EdwardCooke avatar Sep 16 '25 20:09 EdwardCooke

If i don't remove it, I will get an Exception that it is already registered.

TheBigNeo avatar Sep 16 '25 20:09 TheBigNeo