-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ppx: add to_json_string,of_json_string,json_string derivers
- Loading branch information
1 parent
0b7c68a
commit 439391c
Showing
10 changed files
with
229 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open Ppx_deriving_json_runtime.Primitives | ||
|
||
let print fmt = Printf.ksprintf print_endline fmt | ||
|
||
module To_json_string = struct | ||
type ('a, 'b) t = A of 'a | B of 'b | ||
[@@deriving to_json, to_json_string] | ||
|
||
let test () = | ||
let to_json_string = to_json_string int_to_json bool_to_json in | ||
print "** To_json_string **"; | ||
print "A 42 -> %s" (to_json_string (A 42)); | ||
print "B false -> %s" (to_json_string (B false)) | ||
end | ||
|
||
module Of_json_string = struct | ||
type ('a, 'b) t = A of 'a | B of 'b | ||
[@@deriving of_json, of_json_string] | ||
|
||
let test () = | ||
let of_json_string = of_json_string int_of_json bool_of_json in | ||
print "** Of_json_string **"; | ||
print {|["A", 42] = A 42 -> %b|} (of_json_string {|["A", 42]|} = A 42); | ||
print {|["B", false] = B false -> %b|} | ||
(of_json_string {|["B", false]|} = B false) | ||
end | ||
|
||
module Json_string = struct | ||
type ('a, 'b) t = A of 'a | B of 'b [@@deriving json, json_string] | ||
|
||
let test () = | ||
print "** Json_string **"; | ||
let to_json_string = to_json_string int_to_json bool_to_json in | ||
print "A 42 -> %s" (to_json_string (A 42)); | ||
print "B false -> %s" (to_json_string (B false)); | ||
let of_json_string = of_json_string int_of_json bool_of_json in | ||
print {|["A", 42] = A 42 -> %b|} (of_json_string {|["A", 42]|} = A 42); | ||
print {|["B", false] = B false -> %b|} | ||
(of_json_string {|["B", false]|} = B false) | ||
end | ||
|
||
let test () = | ||
To_json_string.test (); | ||
Of_json_string.test (); | ||
Json_string.test () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters