{@inheritDoc}

Template implementation of the <code>convert()</code> method. Takes care
of handling null and empty string values. Once these basic operations
are handled, will delegate to the <code>doConvert()</code> method of
subclasses.
979822
public Object parse(String value, Class type)
    {
        if (StringUtil.isBlank(value))
        {
            return null;
        }

        return doConvert(value.trim(), type);
    }
968157
@Override
    public T convertFromString(Class<? extends T> cls, String str) {
        try {
            return cls.cast(fromString.invoke(null, str));
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException("Method is not accessible: " + fromString);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ex.getCause();
            }
            throw new RuntimeException(ex.getMessage(), ex.getCause());
        }
    }
164139
public static Object convertExample(String value, String type) {
        if (value == null) {
            return null;
        }

        try {
            switch (type) {
                case "integer":
                    return Integer.valueOf(value);
                case "number":
                    return Float.valueOf(value);
                case "boolean":
                    return Boolean.valueOf(value);
                case "string":
                    return value;
                default:
                    return value;
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
        }
    }
524885
protected Object convertNullValue(Class type) throws ConversionException {
        try {
            return type.isPrimitive() ? Array.get(Array.newInstance(type, 1), 0) : null;
        } catch (Exception e) {
            throw new ConversionException(String.format("Could not convert null to primitive type <%s>", type), e);
        }
    }
447923
@SuppressWarnings("unchecked")
    protected BindingResult<T> doBind(
        ArgumentConversionContext<T> context,
        ConvertibleValues<?> values,
        String annotationValue) {

        return doConvert(doResolve(context, values, annotationValue), context);
    }
240808
private String convertMethodKeyObject(final KeyGenerator methodGenerator, final Object keyValue) {
        String res = "";
        if (keyValue instanceof String) {
            res = (String) keyValue;
        } else {
            try {

                // The default annotation value is toString
                final List<Method> converterList = ClassUtility.retrieveMethodList(keyValue.getClass(), methodGenerator.value());

                Method converter = null;
                for (final Method m : converterList) {
                    if (m.getParameterTypes().length == 0) {
                        converter = m;
                    }
                }

                if (converter == null) {
                    LOGGER.log(METHOD_NOT_FOUND, methodGenerator.value(), keyValue.getClass().getSimpleName());
                } else {
                    // The toString will be called for a string
                    final Object localKey = converter.invoke(keyValue);

                    if (localKey == null) {
                        LOGGER.log(NULL_METHOD_KEY_STRING, converter.getName(), keyValue.getClass().getSimpleName());
                    } else {
                        res = localKey.toString();
                    }
                }
            } catch (final SecurityException e) {
                LOGGER.log(NO_TOSTRING_KEY_METHOD, methodGenerator.value(), keyValue.getClass().getSimpleName(), e);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                LOGGER.log(METHOD_KEY_TOSTRING_FAILURE, methodGenerator.value(), keyValue.getClass().getSimpleName(), e);
            }
        }
        return res + "|";
    }
1303210
@SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object convert(Object source, Class<?> target) throws ConversionException {
        if (target == null) {
            throw new ConversionException("Unable to perform conversion, target was null");
        }
        if (source == null) {
            if (target.isPrimitive()) {
                throw new ConversionException(String.format("Unable to convert null to primitive value of %s", target));
            }
            return source;
        } else if ((source instanceof Float && ((Float) source).isNaN()) || (source instanceof Double && ((Double) source).isNaN())) {
            // Don't convert NaN values
            return source;
        }
        //		if (BaseConnection.class.isAssignableFrom(source.getClass()) && !target.equals(IConnection.class)) {
        //			log.debug("Conversion failure - source: {} target: {}", source.getClass(), target);
        //			throw new ConversionException("Source is not assignable and target is not equal to IConnection");
        //		}
        if (target.isInstance(source)) {
            return source;
        }
        if (target.isAssignableFrom(source.getClass())) {
            return source;
        }
        if (target.isArray()) {
            return convertToArray(source, target);
        }
        if (target.equals(String.class)) {
            return source.toString();
        }
        if (target.isPrimitive()) {
            return convertToWrappedPrimitive(source, primitiveMap.get(target));
        }
        if (wrapperMap.containsKey(target)) {
            return convertToWrappedPrimitive(source, target);
        }
        if (target.equals(Map.class)) {
            return convertBeanToMap(source);
        }
        if (target.equals(List.class) || target.equals(Collection.class)) {
            if (source.getClass().equals(LinkedHashMap.class)) {
                return convertMapToList((LinkedHashMap<?, ?>) source);
            } else if (source.getClass().isArray()) {
                return convertArrayToList((Object[]) source);
            }
        }
        if (target.equals(Set.class) && source.getClass().isArray()) {
            return convertArrayToSet((Object[]) source);
        }
        if (target.equals(Set.class) && source instanceof List) {
            return new HashSet((List) source);
        }
        if (source instanceof Map) {
            return convertMapToBean((Map) source, target);
        }
        throw new ConversionException(String.format("Unable to preform conversion from %s to %s", source, target));
    }
376182
@Override
	public String convert(ObjectType sourceObject)
	{
		if(sourceObject == null)
			return null;
		
		String methodName = null;
		Object value =null;
		StringBuilder csv = new StringBuilder();
		Object[] args = {};
		Method m;

		
		for (Entry<String,Method> entry : this.methods.entrySet())
		{
			m = entry.getValue();
			methodName = m.getName();
			
			if(methodName.equals("getClass"))
				continue;
			
			try
			{
				value = m.invoke(sourceObject, args);
				
				if(csv.length() != 0)
					csv.append(SEPARATOR);
				
				csv.append(QUOTE).append(format(value)).append(QUOTE);
				
			}
			catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException e)
			{
				throw new RuntimeException("Unable to get property for method:"+methodName+" error:"+e.getMessage(),e);
			}
		}
		
		csv.append(NEWLINE);
		
		return csv.toString();
		
	}
1306195
@Override
	public Collection<?> convert(Object value, Collection<?> defaultValue) throws IllegalArgumentException {
		Collection<?> result = null;
		try {
			result = convertInternal(value);
		} catch (RuntimeException e) {
			return defaultValue;
		}
		return ((null == result) ? defaultValue : result);
	}
162531
@Nullable
  private static Converter<List<String>, Object> createPrimitiveTypeConverter(final Class<?> resultClass) {
    Object defaultValue = defaultValue(resultClass);

    if (defaultValue == null) {
      // For primitive type, the default value shouldn't be null
      return null;
    }

    return new BasicConverter(defaultValue) {
      @Override
      protected Object convert(String value) throws Exception {
        return valueOf(value, resultClass);
      }
    };
  }
1180581
@Override
    public Object convert(String value) {
        if (value == null || value.isEmpty()) {
            return value;
        }

        Object result = Ints.tryParse(value);

        if (result != null) {
            return result;
        }

        result = Longs.tryParse(value);

        if (result != null) {
            return result;
        }

        result = Doubles.tryParse(value);

        if (result != null) {
            return result;
        }

        return value;
    }
29089
@Override
    public Object convertUponGet(
                    final Object value
                    )
    {
        if (value == null) {
            return null;
        }

        return _formatter.format( (Date)value );
    }
1217982
public Object convert(Class<?> targetType, Object value) {
        if (value == null) {
            return null;
        }

        Converter converter = getConverter(value.getClass(), targetType);
        if (converter == null) {
            throw new IllegalArgumentException(
                    "No converter from " + value.getClass() + " to " + targetType.getName());
        } else {
            return converter.convert(targetType, value);
        }
    }
94124
final public function formatYesNo($nullConvertValue = null)
    {
        $convertedValue = is_null($this->value) ? $nullConvertValue : $this->value;
        if(is_null($convertedValue)) {
            return null;
        } else {
            return $convertedValue ? 'Yes' : 'No';
        }
    }
166362
@Override
    protected String convertToString(Object value) throws Throwable {
		Text text = (Text) value;
		return text.getValue();
    }
1090688
public Object convertFormValueToModelValue(Object propertyValue) {
    if (propertyValue==null || "".equals(propertyValue)) {
      return null;
    }
    return Boolean.valueOf(propertyValue.toString());
  }
447594
@Override
    public Object convert(Object value) {
       if(value instanceof Element) {
           return parseXmlElement((Element) value);
       }
       if(value instanceof CompositeData) {
           return toMap((CompositeData)value);
       }
       return value;
    }