You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ArrayNodeDeserializer leverages CollectionNodeDeserializer.DeserializeHelper to deserialize nodes, however, because it doesn't know the final size of the array being deserialized it uses an ArrayList as a temporary result bucket. Because the IList result it passed into CollectionNodeDeserializer.DeserializeHelper is not the final array, any ValuePromises that get eventually resolved here are not reflected in the final array.
You will need to configure your deserialisation builder as follows to use it:
var namingConvention = YamlDotNet.Serialization.NamingConventions.NullNamingConvention.Instance;
var builder =
new DeserializerBuilder()
.WithNamingConvention(namingConvention)
.WithNodeDeserializer(
inner => new AnchorSafeArrayNodeDeserializer(namingConvention),
s => s.InsteadOf<ArrayNodeDeserializer>());
It should be noted that the provided AnchorSafeArrayNodeDeserializer uses the BCL ArrayList rather than the version originally defined inline. As such, this solution will probably need to be adjusted if used in a PR.
I would create a PR myself, but I just don't have the time at the moment. I hope this still helps people.
If it helps, I believe the following yaml should reproduce the original issue:
When deserialized the obj.items[1].groups array will have a null first entry.
The text was updated successfully, but these errors were encountered:
MetaFight
changed the title
ArrayNodeDeserializer does not handle ValuePromise resolution correctly
Aliases do not resolve correctly in Sequences
Jun 17, 2024
https://github.com/aaubry/YamlDotNet/blob/23991bd3d22009f7478e9e5c3ac71b106a8da3b7/YamlDotNet/Serialization/NodeDeserializers/ArrayNodeDeserializer.cs#L48C13-L53C1
The
ArrayNodeDeserializer
leveragesCollectionNodeDeserializer.DeserializeHelper
to deserialize nodes, however, because it doesn't know the final size of the array being deserialized it uses anArrayList
as a temporary result bucket. Because theIList result
it passed intoCollectionNodeDeserializer.DeserializeHelper
is not the final array, anyValuePromises
that get eventually resolved here are not reflected in the final array.I have been able to get around this by using the attached replacement AnchorSafeArrayNodeDeserializer.cs.
You will need to configure your deserialisation builder as follows to use it:
It should be noted that the provided
AnchorSafeArrayNodeDeserializer
uses the BCLArrayList
rather than the version originally defined inline. As such, this solution will probably need to be adjusted if used in a PR.I would create a PR myself, but I just don't have the time at the moment. I hope this still helps people.
If it helps, I believe the following yaml should reproduce the original issue:
When deserialized the
obj.items[1].groups
array will have anull
first entry.The text was updated successfully, but these errors were encountered: