https://pantsbuild.org/ logo
#development
Title
# development
c

careful-address-89803

09/30/2022, 5:31 AM
hey folks, do we have a policy around implementing serialisation? in my work on dumping source analysis for python, I'm dumping a lot of our classes. Dataclasses has a builtin
dataclasses.asdict
, which works well enough for dataclasses, but many of our types aren't (json) serialisable. Do we have a standard way of doing this? Should I write custom
serialisable
methods? make a custom encoder for JSON?
h

happy-kitchen-89482

09/30/2022, 2:08 PM
We’ve used a custom
JSONEncoder
in a few places, so I guess that?
👍 1
f

fast-nail-55400

09/30/2022, 2:55 PM
We don't really seem to have a standard. For example, in the BSP rules, I ended up writing hand-coded
to_json_dict
and
from_json_dict
for many of the dataclasses (since the JSON format for BSP has differing case requirements).
👍 1
c

careful-address-89803

09/30/2022, 9:21 PM
sounds good. A custom JSONEncoder would be nice, not having to write
str(address)
every time would be nice. We might also want to centralise that, the other source-analysis plugins have an ad-hoc serialiser inside of the rule. maybe having a method/subclass for Console.