Coerce the supplied object to the requested type.

@param obj  The object to be coerced
@param type The type to which the object should be coerced

@return An instance of the requested type.

@throws ELException
If the conversion fails

@since EL 3.0
977138
public Object convertToType(Object obj, Class<?> type) {

        boolean originalResolved = isPropertyResolved();
        setPropertyResolved(false);
        try {
            ELResolver resolver = getELResolver();
            if (resolver != null) {
                Object result = resolver.convertToType(this, obj, type);
                if (isPropertyResolved()) {
                    return result;
                }
            }
        } finally {
            setPropertyResolved(originalResolved);
        }

        return ELManager.getExpressionFactory().coerceToType(obj, type);
    }
1118914
private Object refObj(Object obj, XmlParser.Node node) throws NoSuchMethodException,
            ClassNotFoundException, InvocationTargetException, IllegalAccessException
    {
        String id = node.getAttribute("id");
        obj = _idMap.get(id);
        if (obj == null) throw new IllegalStateException("No object for id=" + id);
        configure(obj, node, 0);
        return obj;
    }
253790
public static DERUTF8String getInstance(
        Object  obj)
    {
        if (obj == null || obj instanceof DERUTF8String)
        {
            return (DERUTF8String)obj;
        }

        if (obj instanceof ASN1OctetString)
        {
            return new DERUTF8String(((ASN1OctetString)obj).getOctets());
        }

        if (obj instanceof ASN1TaggedObject)
        {
            return getInstance(((ASN1TaggedObject)obj).getObject());
        }

        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
    }
735247
public static Object coerceToObject(Object pValue,
                                        Class pClass,
                                        Logger pLogger)
            throws ELException {
        if (pValue == null) {
            return null;
        } else if (pClass.isAssignableFrom(pValue.getClass())) {
            return pValue;
        } else if (pValue instanceof String) {
            String str = (String) pValue;
            PropertyEditor pe = PropertyEditorManager.findEditor(pClass);
            if (pe == null) {
                if ("".equals(str)) {
                    return null;
                } else {
                    if (pLogger.isLoggingError()) {
                        pLogger.logError
                                (Constants.NO_PROPERTY_EDITOR,
                                        str,
                                        pClass.getName());
                    }
                    return null;
                }
            }
            try {
                pe.setAsText(str);
                return pe.getValue();
            }
            catch (IllegalArgumentException exc) {
                if ("".equals(str)) {
                    return null;
                } else {
                    if (pLogger.isLoggingError()) {
                        pLogger.logError
                                (Constants.PROPERTY_EDITOR_ERROR,
                                        exc,
                                        pValue,
                                        pClass.getName());
                    }
                    return null;
                }
            }
        } else {
            if (pLogger.isLoggingError()) {
                pLogger.logError
                        (Constants.COERCE_TO_OBJECT,
                                pValue.getClass().getName(),
                                pClass.getName());
            }
            return null;
        }
    }
1055611
private static GMetricType getType(final Object obj) {

		// FIXME This is far from covering all cases.
		// FIXME Wasteful use of high capacity types (eg Short => INT32)

		// Direct mapping when possible
		if (obj instanceof Long || obj instanceof Integer || obj instanceof Byte || obj instanceof Short)
			return GMetricType.INT32;
		if (obj instanceof Float)
			return GMetricType.FLOAT;
		if (obj instanceof Double)
			return GMetricType.DOUBLE;

		// Convert to double or int if possible
		try {
			Double.parseDouble(obj.toString());
			return GMetricType.DOUBLE;
		} catch (NumberFormatException e) {
			// Not a double
		}
		try {
			Integer.parseInt(obj.toString());
			return GMetricType.UINT32;
		} catch (NumberFormatException e) {
			// Not an int
		}

		return GMetricType.STRING;
	}
599412
def coerce(value, object, type)
      return value if value.nil?

      if type.is_a?(Enumerable)
        objects = value.map { |e| coerce(e, object, type.first) }
        if type.respond_to?(:find_by)
          return type.class.new({}).populate(objects)
        else
          return type.class.new(objects)
        end
      elsif type.ancestors.include? Flickr::Object
        return type.new(value, object.access_token)
      else
        COERCIONS.fetch(type).each do |coercion|
          begin
            return coercion.call(value)
          rescue
          end
        end
      end

      value
    end
1086344
public static Object getObjectElem(Object obj, Object elem, Context cx, Scriptable scope)
    {
        Scriptable sobj = toObjectOrNull(cx, obj, scope);
        if (sobj == null) {
            throw undefReadError(obj, elem);
        }
        return getObjectElem(sobj, elem, cx);
    }
1095124
public static DERUTCTime getInstance(
        Object  obj)
    {
        if (obj == null || obj instanceof DERUTCTime)
        {
            return (DERUTCTime)obj;
        }

        if (obj instanceof ASN1OctetString)
        {
            return new DERUTCTime(((ASN1OctetString)obj).getOctets());
        }

        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
    }
894360
public Obj get(String type, String id) throws Exception {
		return get(type, id, type);
	}
199696
function coerceAll (obj) {
  var type = Array.isArray(obj) ? 'array' : typeof obj;
  var i;
  var n;

  switch (type) {
    case 'string':
      return coerce(obj);
    case 'object':
      if (obj) {
        var props = Object.keys(obj);
        for (i = 0, n = props.length; i < n; i++) {
          var key = props[i];
          obj[key] = coerceAll(obj[key]);
        }
      }
      break;
    case 'array':
      for (i = 0, n = obj.length; i < n; i++) {
        coerceAll(obj[i]);
      }
      break;
  }

  return obj;
}
557787
private Object get(Object obj, Element node) throws Exception {
		Class<?> oClass = nodeClass(node);
		//CHECKSTYLE:OFF
		if (oClass != null) {
			obj = null;
		} else {
			oClass = obj.getClass();
		}
		//CHECKSTYLE:ON

		String name = getAttribute(node, "name");
		String id = getAttribute(node, "id");
		if (LOG.isDebugEnabled()) {
			LOG.debug("XML get " + name);
		}

		//CHECKSTYLE:OFF
		try {
			// try calling a getXxx method.
			Method method = oClass.getMethod("get"
							+ name.substring(0, 1).toUpperCase() + name.substring(1),
					(java.lang.Class[]) null);
			obj = method.invoke(obj, ((java.lang.Object[]) null));
			configure(obj, node, 0);
		} catch (NoSuchMethodException nsme) {
			try {
				Field field = oClass.getField(name);
				obj = field.get(obj);
				configure(obj, node, 0);
			} catch (NoSuchFieldException nsfe) {
				throw nsme;
			}
		}
		//CHECKSTYLE:ON
		if (id != null) {
			_idMap.put(id, obj);
		}
		return obj;
	}
88426
public static <T> T coerceToType(ELContext context, Class<T> toType, Object object) {
        @SuppressWarnings("unchecked")
        T result = (T) getExpressionFactory(context).coerceToType(object, toType);
        return result;
    }
1217063
function isInstance (obj, type) {
  return obj instanceof type ||
    (obj != null && obj.constructor != null && obj.constructor.name != null &&
      obj.constructor.name === type.name)
}
1028837
@Override
	public Object convert(final Object pvObject, final Class<?> pvToType) {
		Object lvResult = pvObject;
		lvResult = interceptorHandler.fireBeforeConvert(lvResult, pvToType);
		try {
			lvResult = convertInternal(lvResult, pvToType);
		} catch (Exception e) {
			interceptorHandler.fireOnError(e);
			if (e instanceof ConversionException) {
				throw (ConversionException) e;
			} else {
				throw new ConversionException(e);
			}
		} finally {
			numberOfRecursion = -1;
			uniqueIdGenerator.clear();
			lvResult = interceptorHandler.fireAfterConvert(lvResult, pvToType);
		}
		
		return lvResult;
	}
478624
protected Object processElement(Object obj, Class<?> expectedType) {
		if (obj == null || obj instanceof Proxy) {
			return obj;
		}
		if (obj instanceof Doc) {
			return wrap(obj);
		} else if (expectedType != null && expectedType.isArray()) {
			final Class<?> componentType = expectedType.getComponentType();
			if (Doc.class.isAssignableFrom(componentType)) {
				final int len = Array.getLength(obj);
				final List<Object> list = new ArrayList<>(len);
				final ApidocExcluder excluder = this.configuration.get().getApidocExcluder();
				for (int i = 0; i < len; ++i) {
					final Object entry = Array.get(obj, i);
					if (!(entry instanceof Doc)) {
						list.add(processElement(entry, componentType));
					} else if (excluder.isExcluded((Doc) entry)) {
						if (excluder.isTranslatableToTag((Doc) entry)) {
							//
						}
					} else {
						list.add(processElement(entry, componentType));
					}
				}
				final Object newArray = Array.newInstance(componentType, list.size());
				int i = 0;
				for (final Object element : list) {
					Array.set(newArray, i, element);
					++i;
				}
				return newArray;
			}
		}
		return obj;
	}
79443
public static ASN1OctetString getInstance(
        Object  obj)
    {
        if (obj == null || obj instanceof ASN1OctetString)
        {
            return (ASN1OctetString)obj;
        }

        if (obj instanceof ASN1TaggedObject)
        {
            return getInstance(((ASN1TaggedObject)obj).getObject());
        }

        if (obj instanceof ASN1Sequence)
        {
            Vector      v = new Vector();
            Enumeration e = ((ASN1Sequence)obj).getObjects();

            while (e.hasMoreElements())
            {
                v.addElement(e.nextElement());
            }

            return new BERConstructedOctetString(v);
        }

        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
    }
707642
public static <T> Conversion<T> to(final Class<T> type) {

		/**
		 * Proxies type conversion to allow for the fact that the value may
		 * provide its own conversion and other subtleties. The goal is to
		 * preserve the identical behavior as if {@link #asType(Class,Object)}
		 * were called.
		 *
		 */
		return new Conversion<T>() {

			@Override
			public Object[] getTypeKeys() {
				Conversion<?> conversion=typeConversions.get(type);
				return (conversion!=null)
					? TypeConverter.getTypeKeys(conversion)
						.toArray(new Object[0])
					: new Object[0];
			}

			@Override
			public T convert(Object value) {
				return TypeConverter.convert(type,value);
			}
		};
	}