Object field injection and JSON serialization mixin extracted from
Objects.Object.
ObjSerialization provides methods for copying attributes between objects,
encoding and decoding object state as JSON, and injecting dictionary values
into object fields. Mixed into Object so all modules inherit serialization
capabilities.
ObjSerialization is a mixin, not a standalone class. It expects the host
class to provide:
self.fields -- list of field names (used by inject/extract methods)self.debug(*args) -- logging methodField-based methods (inject_blank, extract, inject_dictionary) operate
on self.fields to control which attributes are copied. Attribute-based
methods (inject, inject_hidden) use dir() introspection to copy all
public or private attributes.
| Method | Description |
|---|---|
inject(target) |
Copy all public (non-underscore) non-method attributes from self to target |
inject_blank(obj, prefix, filter_) |
Set all fields on obj to empty string, using self.fields as the field list |
inject_hidden(target) |
Copy all private (single-underscore) non-method attributes from self to target |
inject_dictionary(inject_dict) |
Set attributes on self from a dict; keys are title-cased and prefixed with _ (e.g. key name becomes _Name) |
extract(obj, prefix, to_prefix) |
Copy field values from obj to self, using self.fields as the field list. Strips __form_ prefix during extraction. |
encode_class_json() |
Return a dict of self.__dict__ with __class__ and __module__ metadata keys |
encode_json() |
Return a JSON string of encode_class_json() output |
decode_class_json(d) |
Restore object state from a dict; sets private attributes and whitelisted keys (Types, Fields, NumFields) |
decode_json(json_str) |
Parse a JSON string and pass it to decode_class_json() |
Legacy PascalCase aliases are retained for existing callers:
EncodeClassJson = encode_class_jsonEncodeJson = encode_jsonDecodeJson = decode_json