probator.json_utils.
ProbatorJSONEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶Bases: json.encoder.JSONEncoder
Custom JSON encoding function.
This class will check if the object being serialized has a function called to_json(), and call it if available, as well as adding a type-hint value to the output dict (__type key/value pair)
default
(obj)¶Default object encoder function
Parameters: | obj (Any ) – Object to be serialized |
---|---|
Returns: | JSON string |
probator.json_utils.
ProbatorJSONDecoder
(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)¶Bases: json.decoder.JSONDecoder
Custom JSON decoding class
This class will attempt to convert object serialized by ProbatorJSONEncoder
back into Python objects, using
the type-hinting done by the encoder.
object_hook
(obj)¶Checks to see if the __type-hinting field is available in the object being de-serialized. If present, and the class referenced has a from_json function it will return the generated object, else a standard dic will be returned
Parameters: | obj – Object to be deserialized |
---|---|
Returns: | Deserialized object or regular python objec |