-
Notifications
You must be signed in to change notification settings - Fork 0
API Design
Every entity/class which is intended to be encodable and decodable to a JSON document MUST inherit/extend this class
The field decorator is used to mark that a property inside a JSONObject is a JSON field so it will appear in the JSON document when the JSONObject is encoded or decoded
-
field_name (optional) - A name/alias for the
field(how it should appear in the JSON document) since by default the name of thepropertywill be used -
required (optional) - A
boolwhich indicates if thisfieldis mandatory for the decoding process. When afieldwhich is marked as required does NOT exist in the JSON document from which theJSONObjectis decoded from, aConstraintViolationErrorwill be raised (False by default) -
mode (optional) - The
FieldModeof thefield(ENCODE_DECODE by default)
The FieldMode describes the behavior of the field during the encoding/decoding process. It marks that the field should not be in the JSON document when the JSONObject is encoded but it should be decoded and vice versa
- ENCODE - Indicates that the field can ONLY be encoded
- DECODE - Indicates that the field can ONLY be decoded
- ENCODE_DECODE - Indicates that the field can be encoded AND decoded
This class offers methods to encode a JSONObject into a JSON document. A JSONObject can be encoded to
- an
str - a
dict - a
write()supporting file-like object
Encode an instance of a JSONObject into a python dict
-
json_object - The instance of the
JSONObjectwhich should be encoded
-
ConfigurationError When the
JSONObjectof which an instance was passed does NOT define any JSON fields -
TypeError When the type of a
fieldin theJSONObjectis not encodable
A dict which represents the passed JSONObject and is JSON conform
Encode an instance of a JSONObject into an str which contains a JSON document
-
json_object - The instance of the
JSONObjectwhich should be encoded
-
ConfigurationError When the
JSONObjectof which an instance was passed does NOT define any JSON fields -
TypeError When the type of a
fieldin theJSONObjectis not encodable
An str which contains the JSON representation of the passed JSONObject
Encode an instance of a JSONObject and write the result into a write() supporting file-like object
-
json_object - The instance of the
JSONObjectwhich should be encoded -
f - A
write()supporting file-like object
-
ConfigurationError When the
JSONObjectof which an instance was passed does NOT define any JSON fields -
TypeError When the type of a
fieldin theJSONObjectis not encodable
This class offers methods to decode a JSON document into a JSONObject. A JSONObject can be decoded from
- an
str - a
dict - a
write()supporting file-like object
Decode a python dict into a JSONObject. The dict MUST be JSON conform so it cannot contain other object instances
-
json_dict - The
dictwhich should be decoded -
target (optional) - The type of the target
JSONObjectinto which thisdictshould be decoded. When this is empty then the targetJSONObjectwill be searched automatically
-
ConfigurationError When the target
JSONObjectdoes NOT define any JSON fields -
TypeError When the signature of the passed target did NOT match the signature of the passed
dicti.e. they had no fields in common -
MissingObjectError When no target
JSONObjectwas specified AND no matchingJSONObjectcould be found -
ConstraintViolationError When a field inside the
dictviolated a constraint which is defined on the targetJSONObjecte.g. a required field is missing
A JSONObject which matched the signature of the dict and with the values of it
Decode an str into a JSONObject. The str MUST contain a JSON document.
-
json_str - The
strwhich should be decoded -
target (optional) - The type of the target
JSONObjectinto which thisstrshould be decoded. When this is empty then the targetJSONObjectwill be searched automatically
-
ConfigurationError When the target
JSONObjectdoes NOT define any JSON fields -
TypeError When the signature of the passed target did NOT match the signature of the JSON document which was inside the passed
stri.e. they had no fields in common -
MissingObjectError When no target
JSONObjectwas specified AND no matchingJSONObjectcould be found -
ConstraintViolationError When a field of the JSON document which was inside the
strviolated a constraint which is defined on the targetJSONObjecte.g. a required field is missing
A JSONObject which matched the signature of the JSON document from the str and with the values of it
Decode a read() supporting file-like object into a JSONObject. The file-like object MUST contain a valid JSON document.
-
json_file - The
read()supporting file-like object which should be decoded into aJSONObject -
target (optional) - The type of the target
JSONObjectinto which this file-like object should be decoded. When this is empty then the targetJSONObjectwill be searched automatically
-
ConfigurationError When the target
JSONObjectdoes NOT define any JSON fields - TypeError When the signature of the passed target did NOT match the signature of the JSON document which was read from the passed file-like object i.e. they had no fields in common
-
MissingObjectError When no target
JSONObjectwas specified AND no matchingJSONObjectcould be found -
ConstraintViolationError When a field of the JSON document which was read from the file-like object violated a constraint which is defined on the target
JSONObjecte.g. a required field is missing
A JSONObject which matched the signature of the JSON document which the read() supporting file-like object returned and with the values of it
Shortcut for instantiating a JSONEncoder and calling the to_json_file function.
Shortcut for instantiating a JSONEncoder and calling the to_json_str function.
Shortcut for instantiating a JSONEncoder and calling the to_json_dict function.
Shortcut for instantiating a JSONDecoder and calling the from_json_file function.
Shortcut for instantiating a JSONDecoder and calling the from_json_str function.
Shortcut for instantiating a JSONDecoder and calling the from_json_dict function.
The passed JSONObject was not configured correctly
A constraint which has been defined on a field has been violated
No JSONObject which matches the signature of the passed JSON document could be found