Skip to content

NullReferenceException when sub-field of obj contains null #74

@reinux

Description

@reinux

This is OK:

type Test = {
  inside: {| zbc: obj option |}
}

"""
  { "inside": { "zbc": null } }
"""
|> Json.deserializeEx<Test> (JsonConfig.create(allowUntyped = true))

This results in an NRE:

type Test = {
  inside: obj option
}

"""
  { "inside": { "zbc": null } }
"""
|> Json.deserializeEx<Test> (JsonConfig.create(allowUntyped = true))

Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
at FSharp.Json.Core.mapping@1(JsonConfig config, JsonPath path, Type itemValueType, String field0, JsonValue field1)
at FSharp.Json.Core.deserializeMap@399(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
at FSharp.Json.Core.deserializeUnwrapOption@376(JsonConfig config, JsonPath path, Type t, JsonField jsonField, FSharpOption`1 jvalue)
at FSharp.Json.Core.deserializeRecord@463(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
at FSharp.Json.Json.deserializeEx[T](JsonConfig config, String json)
at <StartupCode$FSI_0055>.$FSI_0055.main@() in /home/rei/source/HAInterface/HAInterface/Script1.fsx:line 64
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Stopped due to error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions