diff --git a/FSharp.Json.Tests/AsJson.fs b/FSharp.Json.Tests/AsJson.fs index 59feb9c..b88d350 100644 --- a/FSharp.Json.Tests/AsJson.fs +++ b/FSharp.Json.Tests/AsJson.fs @@ -54,3 +54,10 @@ module AsJson = let actual = Json.deserialize """{"value":null}""" let expected = { AsJsonOptionalRecord.value = None } Assert.AreEqual(expected, actual) + + [] + let ``AsJson member deserialization untyped - null`` () = + let config = JsonConfig.create (jsonFieldNaming = Json.lowerCamelCase, allowUntyped = true ) + let actual = Json.deserializeEx config """[ {"value":null} ]""" + let expected = [ Map.ofList [ "value", None ] ] + Assert.AreEqual(expected[0], actual[0]) diff --git a/FSharp.Json/Core.fs b/FSharp.Json/Core.fs index 6b7af4f..1b704d7 100644 --- a/FSharp.Json/Core.fs +++ b/FSharp.Json/Core.fs @@ -289,7 +289,7 @@ module internal Core = | JsonValue.Record _ -> typeof> | JsonValue.Array _ -> getListType typeof | JsonValue.Boolean _ -> typeof - | _ -> null + | _ -> typeof let rec deserialize (config: JsonConfig) (path: JsonPath) (t: Type) (jvalue: JsonValue): obj = let deserializeEnum (path: JsonPath) (t: Type) (jsonField: JsonField) (jvalue: JsonValue): obj = @@ -368,6 +368,8 @@ module internal Core = JsonValueHelpers.getDateTimeOffset CultureInfo.InvariantCulture path jvalue :> obj | t when t = typeof -> JsonValueHelpers.getGuid path jvalue :> obj + | t when t = typeof -> + None :> obj | t when t.IsEnum -> deserializeEnum path t jsonField jvalue | t when isTuple t || isList t || isArray t || isMap t || isRecord t || isUnion t ->