class SerializerRegistry(object):

    def __init__(self):
        self._classes = {}

def add(self, cls):
    self._classes[cls.__module__, cls.__name__] = cls
return cls

def object_hook(self, dct):
    module, cls_name = dct.pop('__type__', (None, None))
if cls_name is not None:
    return self._classes[module, cls_name].from_dict(dct)
else:
    return dct

def default(self, obj):
    dct = obj.to_dict()
dct['__type__'] = [type(obj).__module__, type(obj).__name__]
return dct
registry = SerializerRegistry()


@registry.add
class A(object):

    def __init__(self, item1):
        self.item1 = item1

def __repr__(self):
    return str(self.__dict__)

def to_dict(self):
    return dict(item1=self.item1)

@classmethod
def from_dict(cls, dct):
    return cls(**dct)
s = json.dumps(A(1), default=registry.default)
a = json.loads(s, object_hook=registry.object_hook)
Как сделать сериализуемый класс simplejson