Default JSON encoding.

def default(self, obj):
        """Default JSON encoding."""
        try:
            if isinstance(obj, datetime.datetime):
                # do the datetime thing,  or
                encoded = arrow.get(obj).isoformat()
            else:
                # try the normal encoder
                encoded = json.JSONEncoder.default(self, obj)
        except TypeError as e:
            # if that fails, check for the to_dict method,
            if hasattr(obj, 'to_dict') and callable(obj.to_dict):
                # and use it!
                encoded = obj.to_dict()
            else:
                raise e
        return encoded