def simplejson_datetime_serializer(obj):
    """
    Designed to be passed as the default kwarg in simplejson.dumps.  Serializes dates and datetimes to ISO strings.
    """
    if hasattr(obj, 'isoformat'):
        return obj.isoformat()
    else:
        raise TypeError(
            'Object of type %s with value of %s is not JSON serializable' %
            (type(obj), repr(obj)))
