<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode(obj, outtype='json', raise_error=False):
 """ encode objects, via encoder plugins, to new types Parameters outtype: str use encoder method to_<outtype> to encode raise_error : bool if True, raise ValueError if no suitable plugin found Examples -------- [] {'_python_Decimal_': '1.3425345'} '1.3425345' {'_python_set_': [1, 2, 3, 4]} '{1, 2, 3, 4}' """

    for encoder in get_plugins('encoders').values():
        if (isinstance(obj, encoder.objclass)
                and hasattr(encoder, 'to_{}'.format(outtype))):
            return getattr(encoder, 'to_{}'.format(outtype))(obj)
            break

    if raise_error:
        raise ValueError(
            "No JSON serializer is available for"
            "{0} (of type {1})".format(obj, type(obj)))
    else:
        return obj