code: private Object convert(Object value, Class type) {
  
  		Object convertedObject = null;
  
  		if (type.equals(String.class)) {
  
  			// strings can be returned immediately
  			return value.toString();
  
  		} else if (value instanceof Number) {
  
  			Number number = (Number) value;
  
  			if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
  				return number.intValue();
  
  			} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
  				return number.longValue();
  
  			} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
  				return number.doubleValue();
  
  			} else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
  				return number.floatValue();
  
  			} else if (type.equals(Short.class) || type.equals(Integer.TYPE)) {
  				return number.shortValue();
  
  			} else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
  				return number.byteValue();
  
  			}
  
  		} else if (value instanceof List) {
  
  			return value;
  
  		} else if (value instanceof Map) {
  			return value;
  		}
  
  		// fallback
  		try {
  
  			Method valueOf = type.getMethod("valueOf", String.class);
  			if (valueOf != null) {
  
  				convertedObject = valueOf.invoke(null, value.toString());
  
  			} else {
  
  				logger.warn("Unable to find static valueOf method for type {}", type);
  			}
  
  		} catch (Throwable t) {
  
  			logger.warn("Unable to deserialize value {} of type {}, Class has no static valueOf method.", new Object[]{value, type});
  		}
  
  		return convertedObject;
  	}
docs: /*
  Tries to convert the given value into an object
  of the given type, using an intermediate type
  of String for the conversion.