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
Empty strings are technically valid YAML but will not return a valid type instance. Despite the interface definition, IDeserializer will return null if given an empty string (or anything that cannot be deserialized into the given type). It seems this library assumes that IDeserializer will always return a valid JToken instance before calling ToObject(). Since Newtonsoft.Json doesn't throw an exception on empty documents, but returns null instead, I would suggest changing the return type to T? (and object? for the non-generic methods) and check the IDeserializer result for null before calling ToObject(). Might also be a good idea to support nullability in the library as a whole.
I have also created an issue on the YamlDotNet repository regarding the incorrect return types in their interface.
My current workaround is now checking the input string for valid, non-empty YAML document content which seems a bit redundant since the underlying converters do that already.
Regardless of this issue, great work on this library. It helped me a ton to avoid rewriting a large number of JSON converters just to support YAML.
The text was updated successfully, but these errors were encountered:
Empty strings are technically valid YAML but will not return a valid type instance. Despite the interface definition,
IDeserializer
will returnnull
if given an empty string (or anything that cannot be deserialized into the given type). It seems this library assumes thatIDeserializer
will always return a validJToken
instance before callingToObject()
. SinceNewtonsoft.Json
doesn't throw an exception on empty documents, but returnsnull
instead, I would suggest changing the return type toT?
(andobject?
for the non-generic methods) and check theIDeserializer
result for null before callingToObject()
. Might also be a good idea to support nullability in the library as a whole.https://github.com/tomlm/YamlConvert/blob/8fe35eed2b8b4d324e63d09c02fa6d6e9355a3fe/YamlConvert/YamlConvert.cs#L80C1-L85C10
With null-check:
With proper return type and null-check (assuming nullability is enabled on the library):
I have also created an issue on the
YamlDotNet
repository regarding the incorrect return types in their interface.My current workaround is now checking the input string for valid, non-empty YAML document content which seems a bit redundant since the underlying converters do that already.
Regardless of this issue, great work on this library. It helped me a ton to avoid rewriting a large number of JSON converters just to support YAML.
The text was updated successfully, but these errors were encountered: