ppx_deriving_yojson icon indicating copy to clipboard operation
ppx_deriving_yojson copied to clipboard

Handling of Map, Set, ...

Open zoggy opened this issue 9 years ago • 2 comments

Do you plan to handle types generated with Map.Make, Set.Make and so on, for example using something like

module Key = struct type t = int let compare = compare end
module Int_map = Map.Make(Key)[@@deriving yojson]

The attribute on a module could mean "derive for all types in the module". I don't know if it's easy, since the Map.S.t is abstract. But may be you could use the Map functions to list elements to create the json structure and re-create the map when reading the json structure.

It might be quite ad-hoc, but useful :)

zoggy avatar Oct 24 '14 07:10 zoggy

If Key.t implements the deriving yojson interface, this can be made possible. But first I think I'll need to handle regular, non-functor versions of Map and Hashtbl...

whitequark avatar Oct 24 '14 11:10 whitequark

FYI: it's not the sort of automatic derivation that is envisaged here, but a workaround is now available on master via the @to_yojson and @of_yojson attributes (analogous to the show's @printer attribute).

cemerick avatar Oct 09 '19 18:10 cemerick