# -*- coding: utf-8 -*-

import json as _json

from functools import partial


__all__ = ('dumps', 'loads', )


class JSONEncoder(_json.JSONEncoder):

    def default(self, obj):
        if hasattr(obj, 'to_primitive'):
            result = obj.to_primitive()
        elif hasattr(obj, 'isoformat'):
            result = obj.isoformat()
        else:
            result = super().default(obj)

        return result


def object_decoder(obj):
    return obj


dumps = partial(_json.dumps, cls=JSONEncoder)
loads = partial(_json.loads, object_hook=object_decoder)

@@ -71,16 +71,56 @@
 artial%0A%0A
+from il2fb.commons.events import Event%0A%0A
 %0A__all__
@@ -249,24 +249,57 @@
 rimitive'):%0A
+            cls = obj.__class__%0A%0A
             
@@ -326,16 +326,203 @@
 itive()%0A
+            result%5B'__type__'%5D = f%22%7Bcls.__module__%7D.%7Bcls.__name__%7D%22%0A%0A            if issubclass(cls, Event):%0A                result.pop('name')%0A                result.pop('verbose_name')%0A%0A
         

Update custom JSON encoder