diff --git a/src/compiler/WebSharper.Compiler/QuotationReader.fs b/src/compiler/WebSharper.Compiler/QuotationReader.fs index 6291d2af8..e43507ad4 100644 --- a/src/compiler/WebSharper.Compiler/QuotationReader.fs +++ b/src/compiler/WebSharper.Compiler/QuotationReader.fs @@ -153,7 +153,7 @@ let rec transformExpression (env: Environment) (expr: Expr) = | _ -> expr :: acc getSeq [] expr |> List.rev |> List.map tr |> Sequential | Patterns.Value (value, _) -> - if obj.ReferenceEquals(value, null) then Value Null else + if isNull value then Value Null else try let value = let t = value.GetType() diff --git a/src/compiler/WebSharper.Core/Json.fs b/src/compiler/WebSharper.Core/Json.fs index 2adad5b3d..fa6eea101 100644 --- a/src/compiler/WebSharper.Core/Json.fs +++ b/src/compiler/WebSharper.Core/Json.fs @@ -287,8 +287,7 @@ let rec Write (writer: System.IO.TextWriter) (value: Value) = else raise WriteException let wS (x: string) = - if x = null then - raise WriteException + if x = null then s "null" else c '"' for i in 0 .. x.Length - 1 do match x.[i] with @@ -586,6 +585,7 @@ let serializers = | x -> raise (DecoderException(x, typeof)) add encChar decChar d let decString = function + | Null -> null | String x -> x | x -> raise (DecoderException(x, typeof)) add EncodedString decString d @@ -1004,6 +1004,10 @@ let unionDecoder dD (i: FormatSettings) (ta: TAttrs) = for k, v in c do consts.Add(k, v) consts let getTag = i.GetUnionTag t + let nullConstant = + match consts.TryGetValue (String null) with + | true, x -> x + | false, _ -> null fun (x: Value) -> match x with | Object fields -> @@ -1016,7 +1020,7 @@ let unionDecoder dD (i: FormatSettings) (ta: TAttrs) = fs |> Array.map (fun (f, e) -> e (get f)) |> mk - | Null -> null + | Null -> nullConstant | v -> match consts.TryGetValue v with | true, x -> x