MCPcopy Index your code
hub / github.com/USArmyResearchLab/Dshell / json_default

Method json_default

dshell/output/jsonout.py:32–46  ·  view source on GitHub ↗

JSON serializer for objects not serializable by default json code https://stackoverflow.com/a/22238613

(self, obj)

Source from the content-addressed store, hash-verified

30 super().write(jsondata=jsondata)
31
32 def json_default(self, obj):
33 """
34 JSON serializer for objects not serializable by default json code
35 https://stackoverflow.com/a/22238613
36 """
37 if isinstance(obj, datetime):
38 serial = obj.strftime(self.timeformat)
39 return serial
40 if isinstance(obj, bytes):
41 serial = repr(obj)
42 return serial
43 if isinstance(obj, (Connection, Blob, Packet)):
44 serial = obj.info()
45 return serial
46 raise TypeError ("Type not serializable ({})".format(str(type(obj))))
47
48obj = JSONOutput

Callers

nothing calls this directly

Calls 1

infoMethod · 0.45

Tested by

no test coverage detected