microsoft/fsharplu

Nested optional algaebric datatype cannot be deserialized

Closed this issue · 1 comments

blumu commented

Following code:

type A =
    {
        subField1 : int
        subField2 : int
    }
type B =
    {
        field : A option
    }

let x = { field = Some { subField1 = 1 ; subField2 = 2 } }

let json = Microsoft.FSharpLu.Json.Compact.serialize<B> x
Microsoft.FSharpLu.Json.Compact.deserialize<B> json 

throws the following exception

System.Exception: Nested option types must be serialized as boxed Json objects with attribute 'Some'.
>    at <StartupCode$Microsoft-FSharpLu-Json>.$Compact.parseBox@92(JsonSerializer serializer, Type nestedType, JToken jToken)
   at Microsoft.FSharpLu.Json.CompactUnionJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType, IDictionary`2& extensionData)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Microsoft.FSharpLu.Json.Compact.deserialize[T](String json)
   at <StartupCode$FSI_0035>.$FSI_0035.main@() in D:\sources\Springfield\source\Script1.fsx:line 161

blumu commented

Fixed by PR #4