You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most libraries don't come with of_yojson and yojson_of functions. It would be very useful to be able to provide a custom module with (de)serialization functions or direct references to the functions.
An example of what direct references to custom functions might look like:
Those two functions can be wrapped in a module easily enough. However, that wrapping would make the type t definition more difficult to understand because we'd no longer see directly in the type that timestamp is a Time_ns.t.
In this case we could directly replace timestamp : Time_ns.t with timestamp : Json.Time_ns.t but that requires a person reading the code to check and see what the definition of Json.Time_ns.t is. Specifying a custom module avoids placing that burden on reader.
The text was updated successfully, but these errors were encountered:
This would also help when using other ppx derivers alongside ppx_yojson_conv. For example, when using ppx_compare and [@@deriving equal, yojson] the following example would need an additional [@@deriving equal] on the type t = Time_ns.t alias as the deriver currently exists. With support for a syntax like the [@yojson.module Json.Time_ns] example above that extra annotation wouldn't be needed.
moduleJson=structmoduleTime_ns=structtypet = Time_ns.tlett_of_yojsonjson=match json with|`Strings -> Time_ns.of_string s
|_ -> failwith "Invalid time"
;;
letyojson_of_ttime=`String (Time.to_string time)
endendtypet = {
label : string;timestamp : Json.Time_ns.t;
}
[@@deriving equal, yojson]
(* This will give an error because [Json.Time_ns.equal] does not exist *)
Most libraries don't come with
of_yojson
andyojson_of
functions. It would be very useful to be able to provide a custom module with (de)serialization functions or direct references to the functions.An example of what direct references to custom functions might look like:
Those two functions can be wrapped in a module easily enough. However, that wrapping would make the
type t
definition more difficult to understand because we'd no longer see directly in the type thattimestamp
is aTime_ns.t
.An example with a custom module:
In this case we could directly replace
timestamp : Time_ns.t
withtimestamp : Json.Time_ns.t
but that requires a person reading the code to check and see what the definition ofJson.Time_ns.t
is. Specifying a custom module avoids placing that burden on reader.The text was updated successfully, but these errors were encountered: