aaubry / YamlDotNet

YamlDotNet is a .NET library for YAML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for FSharp BCL List deserialization

MrLuje opened this issue · comments

While looking at #913, I noticed that there is currently no support for F# List.

In F# BCL, there is basically 3 main collections :

  • seq (= C# IEnumerable)
  • array (= C# Array)
  • list which is an ordered immutable list
#r "nuget: YamlDotNet"

open YamlDotNet

[<CLIMutable>]
type MyType = { 
    Numbers: int list 
}

open YamlDotNet.Serialization

let d = Deserializer()
"""
Numbers: [1, 2, 3]
"""
|> d.Deserialize<MyType>
|> printfn "%A"

gives the following error :

(Line: 2, Col: 10, Idx: 10) - (Line: 2, Col: 10, Idx: 10): No node deserializer was able to deserialize the node into type Microsoft.FSharp.Collections.FSharpList`1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Stopped due to error

If that's ok, I can add support for it, following the same approach as #930 (probably by adding a new deserializer in DeserializerBuilder)