Return an _AggregateConverter for a user object of the given class.

def _user_object_converter(cls):
    # type: (Type[Any]) -> _AggregateConverter
    """Return an _AggregateConverter for a user object of the given class."""
    def _from_dict(dict_value):
        try:
            object_value = cls(**dict_value)
        except TypeError:
            # Constructor does not support keyword arguments, try setting each
            # field individually.
            object_value = cls()
            for field_name, field_value in dict_value.items():
                setattr(object_value, field_name, field_value)

        return object_value

    def _to_dict(value):
        if value:
            return value.__dict__

        return {}

    return _AggregateConverter(from_dict=_from_dict, to_dict=_to_dict)