def to_json_serializable(cls, obj): amap = {} for k, v in obj.items(): kk = Base.to_json_data(value_type=(k, cls.ktype)) vv = Base.to_json_data(value_type=(v, cls.vtype)) amap[kk] = vv return amap
def to_json_serializable(self): amap = {} for name, atype in self._fields: value = getattr(self, name) atype = type_mapping(atype) amap[name] = Base.to_json_data(value_type=(value, atype)) return amap
def to_json_serializable(cls, obj): if cls.atype == Uint8: return struct.pack("<{}B".format(len(obj)), *obj).hex() ret = [] for _, item in enumerate(obj): data = Base.to_json_data(value_type=(item, cls.atype)) ret.append(data) return ret
def to_json_serializable(cls, obj): ret = [] #https://stackoverflow.com/questions/15721363/preserve-python-tuples-with-json #If need to deserialize tuple back later, above link will help. zipped = zip(cls.ttypes, obj) for k, v in zipped: data = Base.to_json_data(value_type=(v, k)) ret.append(data) return ret
def to_json_serializable(self): jj = Base.to_json_data(value_type=(self.value, self.value_type)) return {self.enum_name: jj}
def to_json_serializable(self): if self.value is None: return None return Base.to_json_data(value_type=(self.value, self.value_type))
def to_json_serializable(cls, value): #if hasattr(cls, "to_json_serializable"): if 'to_json_serializable' in cls.__dict__.keys(): return cls.to_json_serializable(value) return Base.to_json_data(value_type=(value, cls.dtype()))