Returns a casted object of the input value string based on the given type
@throws ParseException
182515
public static Object getObjectFromString(VoltType type, String value)
    throws ParseException
    {
        Object ret = null;
        switch (type) {
            // NOTE: All runtime integer parameters are actually Longs,so we will have problems
            // if we actually try to convert the object to one of the smaller numeric sizes

            // --------------------------------
            // INTEGERS
            // --------------------------------
            case TINYINT:
                //ret = Byte.valueOf(value);
                //break;
            case SMALLINT:
                //ret = Short.valueOf(value);
                //break;
            case INTEGER:
                //ret = Integer.valueOf(value);
                //break;
            case BIGINT:
                ret = Long.valueOf(value);
                break;
            // --------------------------------
            // FLOATS
            // --------------------------------
            case FLOAT:
                ret = Double.valueOf(value);
                break;
            // --------------------------------
            // STRINGS
            // --------------------------------
            case STRING:
                ret = value;
                break;

            case DECIMAL:
            case VARBINARY:
                if (value != null) {
                    throw new RuntimeException("Only NULL default values for DECIMAL " +
                            "and VARBINARY columns are supported right now");
                }
                break;
            // --------------------------------
            // TIMESTAMP
            // --------------------------------
            case TIMESTAMP: {
                // Support either long values (microseconds since epoch) or timestamp strings.
                try {
                    // Try to parse it as a long first.
                    ret = new TimestampType(Long.parseLong(value));
                }
                catch (NumberFormatException e) {
                    // It failed to parse as a long - parse it as a timestamp string.
                    Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(value);
                    ret = new TimestampType(date.getTime() * 1000);
                }
                break;
            }
            // --------------------------------
            // INVALID
            // --------------------------------
            default:
                LOG.severe("ERROR: Unable to get object from string for invalid ValueType '" + type + "'");
        }
        return (ret);
    }
1240466
static <T> T cast(Object obj, Class<T> type) {
        if (type == String.class) {
            if (obj == null)
                obj = "";
            obj = obj.toString();
        } else if (type == BigInteger.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            obj = new BigInteger("" + obj);
        } else if (type == BigDecimal.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            obj = new BigDecimal(("" + obj).replace(",","."));
        } else if (type == Integer.class || type == int.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            if(obj instanceof Integer){

            }else
                obj = new BigDecimal(""+obj).intValue();
        } else if (type == Long.class || type==long.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            if(obj instanceof Long){

            }else
                obj = new BigDecimal(("" + obj).replace(",",".")).longValue();
        } else if (type == Float.class || type==float.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            if(obj instanceof Float){

            }else
                obj = new BigDecimal(("" + obj).replace(",",".")).floatValue();
        } else if (type == Double.class || type==double.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "0";
            if(obj instanceof Double){

            }else
                obj = new BigDecimal(("" + obj).replace(",",".")).doubleValue();
        } else if (type == Boolean.class || type==boolean.class) {
            if (obj == null || (""+obj).isEmpty())
                obj = "false";
            if(obj instanceof Number){
                obj = ((Number) obj).intValue()!=0;
            }else
                obj = Boolean.parseBoolean("" + obj);
        } else if (type == Date.class) {
            if((""+obj).isEmpty())
                obj = null;
            if (obj != null) {
                if (obj instanceof String) {
                    Date dt = null;
                    SimpleDateFormat[] sdf = new SimpleDateFormat[]{
                            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"),
                            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),
                            new SimpleDateFormat("yyyy-MM-dd HH:mm"),
                            new SimpleDateFormat("yyyy-MM-dd")
                    };
                    for(SimpleDateFormat s:sdf){
                        try {
                            dt = s.parse("" + obj);
                            break;
                        }catch (Throwable e){}
                    }
                    if(dt==null)
                        dt = new Date(Long.parseLong("" + obj));
                    obj = dt;
                } else if (obj instanceof Long) {
                    obj = new Date((Long) obj);
                }
            }
        } else if(type.isEnum()){
            if(obj != null && obj instanceof String){
                obj = Enum.valueOf((Class<? extends Enum>)type,((String) obj).toUpperCase());
            }
        }

        return (T) obj;
    }
979822
public Object parse(String value, Class type)
    {
        if (StringUtil.isBlank(value))
        {
            return null;
        }

        return doConvert(value.trim(), type);
    }
590898
public Object parseValue() {
    Object val;
    switch(T.getType()) {
      case LCURLY:
        val = parseObject();
        break;
      case LSQUARE:
        val = parseArray();
        break;
      case INTEGER:
        if(useBig) {
          val = new BigInteger(T.getString());
        } else {
          try {
            val = Integer.parseInt(T.getString());
          } catch(NumberFormatException e0) {
            // we have an overflow, the tokenizer guarantees the format is correct
            try {
              val = Long.parseLong(T.getString());
            } catch(NumberFormatException e1) {
              val = 0;
            }
          }
        }
        advance();
        break;
      case DOUBLE:
        if(useBig) {
          val = new BigDecimal(T.getString());
        } else {
          val = Double.parseDouble(T.getString());
        }
        advance();
        break;
      case STRING:
        val = T.getString();
        advance();
        break;
      case TRUE:
        val = true;
        advance();
        break;
      case FALSE:
        val = false;
        advance();
        break;
      case NULL:
        val = null;
        advance();
        break;
      default:
        val = null;
        addError();
    }
    return val;
  }
814182
protected function cast($value = null, int $type = Variables::TYPE_STRING)
    {
        if ($value === null) {
            return $this->getDefault($type);
        }
        switch ($type) {
            case Variables::TYPE_INT:
                $value = @\intval($value);
                break;
            case Variables::TYPE_FLOAT:
                $value = @\floatval($value);
                break;
            case Variables::TYPE_STRING:
                $value = @\strval($value);
                break;
            case Variables::TYPE_ARRAY:
                $value = (array)$value;
                break;
            case Variables::TYPE_JSON_DECODED:
                $value = @\json_decode(@\strval($value), true, 512) ?: '';
                break;
            case Variables::TYPE_AUTO:
                break;
            default:
                throw new DomainException('Invalid variable type specified');
                break;
        }
        return $value;
    }
804599
protected Object getTypedValue(int type, byte[] value)
   {
      Object result;

      switch (type)
      {
         case 4: // Date
         {
            result = MPPUtility.getTimestamp(value, 0);
            break;
         }

         case 6: // Duration
         {
            TimeUnit units = MPPUtility.getDurationTimeUnits(MPPUtility.getShort(value, 4), m_properties.getDefaultDurationUnits());
            result = MPPUtility.getAdjustedDuration(m_properties, MPPUtility.getInt(value, 0), units);
            break;
         }

         case 9: // Cost
         {
            result = Double.valueOf(MPPUtility.getDouble(value, 0) / 100);
            break;
         }

         case 15: // Number
         {
            result = Double.valueOf(MPPUtility.getDouble(value, 0));
            break;
         }

         case 36058:
         case 21: // Text
         {
            result = MPPUtility.getUnicodeString(value, 0);
            break;
         }

         default:
         {
            result = value;
            break;
         }
      }

      return result;
   }
1318731
def _cast_to_type(self, value):
        
        if not isinstance(value, dict):
            self.fail('invalid', value=value)
        return value
1014604
@SuppressWarnings("unchecked")
    public static <T> T castToType(final Class<T> type, final Object val) throws DevFailed {

	T result;
	if (val == null) {
	    result = null;
	} else if (type.isAssignableFrom(val.getClass())) {
	    result = (T) val;
	} else {
	    LOGGER.debug("converting {} to {}", val.getClass().getCanonicalName(), type.getCanonicalName());
	    // if input is not an array and we want to convert it to an array.
	    // Put
	    // the value in an array
	    Object array = val;
	    if (!val.getClass().isArray() && type.isArray()) {
		array = Array.newInstance(val.getClass(), 1);
		Array.set(array, 0, val);
	    }
	    final Transmorph transmorph = new Transmorph(creatConv());
	    try {
		result = transmorph.convert(array, type);
	    } catch (final ConverterException e) {
		LOGGER.error("convertion error", e);
		throw DevFailedUtils.newDevFailed(e);
	    }
	}
	return result;
    }
1014771
function cast(type, variable) {
		var result = variable;

		switch (type) {
			case 'number':
				result = +result;
				break;

			case 'int':
				result = parseInt(result, 10);
				break;

			case 'float':
				result = parseFloat(result);
				break;

			case 'bool':
			case 'boolean':
				result = ['true', '1', 1].indexOf(result) >= 0;
				break;
		}

		return result;
	}
1023650
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;
	}
871112
def cast_type(self, var, cast_type=None):
        

        if cast_type is None:
            cast_type = self.valid_values

        try:
            if cast_type == int:
                return int(var)
            elif cast_type == float:
                return float(var)
            elif type == str:
                return str(var)
            elif isinstance(cast_type, list):
                # cast var to be of the same type as those in the list
                return type(cast_type[0])(var)
            else:
                return None
        except ValueError:
            return None

        return var
1192388
public static <T> T deserialize(byte[] input, Class<T> classType)
            throws JsonParseException, JsonMappingException, IOException {
        return mapper.readValue(input, classType);
    }
1048142
@Override
	public Object convert(String value, Class type) {
		if (isNullOrEmpty(value)) {
			return null;
		}

		if (Character.isDigit(value.charAt(0))) {
			return resolveByOrdinal(value, type);
		} else {
			return resolveByName(value, type);
		}
	}
853412
public static Object toObject(Class<?> clazz, Object value) throws ParseException {
        if (value == null) {
            return null;
        }
        if (clazz == null) {
            return value;
        }

        if (java.sql.Date.class.isAssignableFrom(clazz)) {
            return toDate(value);
        }
        if (java.sql.Time.class.isAssignableFrom(clazz)) {
            return toTime(value);
        }
        if (java.sql.Timestamp.class.isAssignableFrom(clazz)) {
            return toTimestamp(value);
        }
        if (java.util.Date.class.isAssignableFrom(clazz)) {
            return toDateTime(value);
        }

        return value;
    }
189884
public static Integer parseInteger(String value) throws ParseException
   {
      Integer result = null;

      if (value.length() > 0 && value.indexOf(' ') == -1)
      {
         if (value.indexOf('.') == -1)
         {
            result = Integer.valueOf(value);
         }
         else
         {
            Number n = DatatypeConverter.parseDouble(value);
            result = Integer.valueOf(n.intValue());
         }
      }

      return result;
   }
1005645
public Object parseType(String input, Type targetType) {
        return typeParser.parseType(input, targetType);
    }
647709
function (value, type) {
    type = type || 'smart';

    switch (type) {
      case 'boolean':
      case 'bool':
        if (typeof value !== 'string') {
          value = !!value;
        } else {
          value = ['null', 'undefined', '0', 'false'].indexOf(value) === -1;
        }

        break;

      case 'string':
      case 'text':
        value = this.cast(value, 'boolean') ? value + '' : null
        break;

      case 'date':
      case 'datetime':
        value = new Date(value);
        break;

      case 'int':
      case 'integer':
      case 'number':
        value = ~~value;
        break;

      case 'float':
        value = parseFloat(value);
        break;

      case 'smart':
        value = this.cast(value, this.detect(value));
        break;

      default:
        throw new Error('Expected valid casting type.');
    }

    return value;
  }