The serialize function could be refactor as is:

```python

    if isinstance(data, (bool, int, long, float, basestring)):
        return data

    if isinstance(data, dict):
        data = data.copy()
        for key in data:
            data[key] = serialize(data[key])
        return data
    
    if isinstance(data, list):
        return [serialize(item) for item in data]
    
    if isinstance(data, tuple):
        return tuple(serialize([item for item in data]))
    
    if hasattr(data, '__dict__'):
        return serialize(data.__dict__)

    return str(data)  # converts to string
```