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
Supporting string (de)serialization for types that do not support yojson functions may help library authors make use of ppx_deriving_yojson. This could use the existing convention of labeling a type with [@encoding string] to do string serialization instead of yojson serialization for large numbers. For example consider the (pseudo) code below:
moduleA : sig(* This module comes from package a *)typetvalto_string : t -> stringvalof_string : string -> tendmoduleB : sig(* This module comes from package b *)typet [@@deriving yojson]endmoduleC : sig(* Somebody's trying to write this module in package c, with a and b as dependencies *)typet =
| Aof (A.t [@encoding `string])
| BofB.t
[@@deriving yojson]
end
The effect here would be that C.to_yojson would encode a B variant normally, but would encode an A variant with the leading "A" tag as usual, while using A.to_string to encode the value that variant contains.
I was looking into implementing this but thought to solicit feedback before proceeding much more. Thoughts?
The text was updated successfully, but these errors were encountered:
To add to my original comment (which I made a few edits to for readability), the most recent time I came across this was while I was using the ipaddr library. Specifically I wanted to serialize an Ipaddr.V4.Prefix.t. Under the hood this is an int32 * int, but for serialization purposes the x.x.x.x/x would satisfactory, if not preferable.
Of course doing the type aliasing and writing the (de)serializers manually would be very simple, but this use-case may warrant special support from the library.
Supporting string (de)serialization for types that do not support yojson functions may help library authors make use of ppx_deriving_yojson. This could use the existing convention of labeling a type with
[@encoding string]
to do string serialization instead of yojson serialization for large numbers. For example consider the (pseudo) code below:The effect here would be that
C.to_yojson
would encode aB
variant normally, but would encode anA
variant with the leading"A"
tag as usual, while usingA.to_string
to encode the value that variant contains.I was looking into implementing this but thought to solicit feedback before proceeding much more. Thoughts?
The text was updated successfully, but these errors were encountered: