def serialize(obj, with_help=False, with_defaults=True):
    """
  Return a serializable representation of the object. If the object has an
  `as_dict` method, then it will call and return the output of that method.
  Otherwise return the object itself.
  """
    if hasattr(obj, 'as_odict'):
        fun = getattr(obj, 'as_odict')
        if callable(fun):
            return fun(with_help=with_help, with_defaults=with_defaults)
    if hasattr(obj, 'as_dict'):
        fun = getattr(obj, 'as_dict')
        if callable(fun):
            return fun(with_help=with_help, with_defaults=with_defaults)
    return obj
