Skip to content

Commit

Permalink
Fix #643 constant null in ClientSideJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Jan 23, 2017
1 parent 70d27a1 commit 29ae02d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sitelets/WebSharper.Web/ClientSideJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module Provider =
let EncodeUnion (_: obj) (discr: string) (cases: (string * (string * string * (unit -> obj -> obj) * OptionalFieldKind)[])[]) : (unit -> 'T -> obj) =
()
fun () x ->
if JS.TypeOf x ===. JS.Object then
if JS.TypeOf x ===. JS.Object && x !=. null then
let o = New []
let tag = x?("$")
let tagName, fields = cases.[tag]
Expand Down
1 change: 1 addition & 0 deletions tests/WebSharper.Sitelets.Tests/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module Json =
| [<Constant "foo">] Foo
| [<Constant "bar">] Bar
| [<Constant 12>] Twelve
| [<Constant null>] Null

type GenericUnion() =

Expand Down
3 changes: 3 additions & 0 deletions tests/WebSharper.Web.Tests/ClientSideJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ module ClientSideJson =
equal (Json.Serialize Foo |> Json.Parse |> unbox) "foo"
equal (Json.Serialize Bar |> Json.Parse |> unbox) "bar"
equal (Json.Serialize Twelve |> Json.Parse |> unbox) 12
equal (Json.Serialize Null |> Json.Parse |> unbox) null
}

Test "deserialize union with constants" {
equal (Json.Deserialize (Json.Stringify "foo")) Foo
equal (Json.Deserialize (Json.Stringify "bar")) Bar
equal (Json.Deserialize (Json.Stringify 12)) Twelve
equal (Json.Deserialize (Json.Stringify null)) Null
}

Test "serialize System.DateTime" {
Expand Down Expand Up @@ -462,6 +464,7 @@ module ClientSideJson =
equalAsync (f Foo) Foo
equalAsync (f Bar) Bar
equalAsync (f Twelve) Twelve
equalAsync (f Null) Null
}

let now = System.DateTime.Now
Expand Down

0 comments on commit 29ae02d

Please sign in to comment.