Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude key from serialization #84

Open
haskellcamargo opened this issue Dec 3, 2018 · 1 comment
Open

Exclude key from serialization #84

haskellcamargo opened this issue Dec 3, 2018 · 1 comment

Comments

@haskellcamargo
Copy link

I'd like to omit some keys (with complex values) from being serialized/deserialized and managed by ppx_deriving_yojson.

type t = {
  class_name: string;
  long_name: bool;
  data_variables: unit declaration Naming.Long_map.t [@default Naming.Long_map.empty];
  methods: method_ declaration Naming.Long_map.t [@default Naming.Long_map.empty]
}
[@@deriving make, to_yojson]

In this situation, I want to serialize class_name and long_name, but I'd like to omit data_variables and methods. How can I force it to not handle them (in a way other than creating a dummy *_to_yojson implementation)?

My suggestion is something like [@opaque] for visitors ppx.

@vphantom
Copy link

vphantom commented Apr 17, 2019

Just FYI, my work-around has been to use [@default …] on those fields like you, and to pass a masked copy of the records of interest to Yojson, with those fields set to their default values. They won't be output.

(Of course, Base/Core redefine (=) to be integer-specific which limits ppx_deriving_yojson's checks for default values (#79), so we have to work around that too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants