cast a Object to a Byte Object(reference type)

@param o Object to cast
@param defaultValue
@return casted Byte Object
421092
public static Short toShort(Object o, Short defaultValue) {
	if (o instanceof Short) return (Short) o;
	if (defaultValue != null) return Short.valueOf(toShortValue(o, defaultValue.shortValue()));
	short res = toShortValue(o, Short.MIN_VALUE);
	if (res == Short.MIN_VALUE) return defaultValue;
	return Short.valueOf(res);
    }
1052598
public static Byte readByte(String value, Byte defaultValue) {
		if (!StringUtils.hasText(value)) return defaultValue;
		
		return Byte.valueOf(value);
	}
395871
public VALUEFROM decodeFromRaw(Object o) {
        if (o == null && !isOptional()) return null;
        return decodeFromRawInternal(o);
    }
850356
public static JsonObject getObject(JsonObject object, String field, JsonObject defaultValue) {
        final JsonValue value = object.get(field);
        if (value == null || value.isNull()) {
            return defaultValue;
        } else {
            return value.asObject();
        }
    }
1331783
public static float toFloatValue(Object o, float defaultValue) {
	if (o instanceof Character) return (((Character) o).charValue());
	else if (o instanceof Boolean) return ((((Boolean) o).booleanValue()) ? 1F : 0F);
	else if (o instanceof Number) return (((Number) o).floatValue());
	else if (o instanceof CharSequence) return (float) toDoubleValue(o.toString(), defaultValue);
	else if (o instanceof Character) return (float) (((Character) o).charValue());
	else if (o instanceof Castable) {
	    return (float) ((Castable) o).castToDoubleValue(defaultValue);

	}
	else if (o instanceof ObjectWrap) return toFloatValue(((ObjectWrap) o).getEmbededObject(toFloat(defaultValue)), defaultValue);

	return defaultValue;
    }
922706
public static String getMimeType(InputStream is, String defaultValue) {
	try {
	    return getMimeType(IOUtil.toBytesMax(is, 1000), defaultValue);
	}
	catch (IOException e) {
	    return defaultValue;
	}
    }
739869
public static Object getPrimitiveDefaultValue(final Class<?> type) {
        ArgUtils.notNull(type, "type");

        if(!type.isPrimitive()) {
            return null;
        }

        if(type.equals(boolean.class)) {
            return false;

        } else if(type.equals(char.class)) {
            return '\u0000';

        } else if(type.equals(byte.class)) {
            return (byte)0;

        } else if(type.equals(short.class)) {
            return (short)0;

        } else if(type.equals(int.class)) {
            return 0;

        } else if(type.equals(long.class)) {
            return 0l;

        } else if(type.equals(float.class)) {
            return 0.0f;

        } else if(type.equals(double.class)) {
            return 0.0d;

        }

        return null;
    }
804317
public static Integer toInteger(Object o, Integer defaultValue) {
	if (defaultValue != null) return Integer.valueOf(toIntValue(o, defaultValue.intValue()));
	int res = toIntValue(o, Integer.MIN_VALUE);
	if (res == Integer.MIN_VALUE) return defaultValue;
	return Integer.valueOf(res);
    }
990568
public static CellValue fromTypeAndObject(final TableCell.Type type, final Object o) {
		// TODO: use the type hint, with a switch...
		return CellValue.fromObject(o);
	}
136712
public static Val of(Object o) {
      if (o != null && o instanceof Val) {
         return Cast.as(o);
      }
      return new Val(o);
   }
659914
public static double toDoubleValue(Object o, boolean alsoFromDate, double defaultValue) {
	if (o instanceof Number) return ((Number) o).doubleValue();
	else if (o instanceof Boolean) return ((Boolean) o).booleanValue() ? 1 : 0;
	else if (o instanceof CharSequence) return toDoubleValue(o.toString(), alsoFromDate, defaultValue);
	else if (o instanceof Castable) {
	    return ((Castable) o).castToDoubleValue(defaultValue);

	}
	// else if(o == null) return defaultValue;
	else if (o instanceof ObjectWrap) return toDoubleValue(((ObjectWrap) o).getEmbededObject(new Double(defaultValue)), true, defaultValue);
	else if (o instanceof Date) return DateTimeUtil.getInstance().toDoubleValue(((Date) o).getTime());
	else if (o instanceof Calendar) return DateTimeUtil.getInstance().toDoubleValue(((Calendar) o).getTimeInMillis());
	else if (o instanceof Character) return (double) (((Character) o).charValue());
	return defaultValue;
    }
788279
public static BigInteger toBigInteger(Object value, BigInteger defaultValue) {
		return convert(BigInteger.class, value, defaultValue);
	}
271708
public static <T extends Enum<T>> T convert(Class<T> type, String name, T defaultValue) {
        if (name == null) {
            return defaultValue;
        }

        for (T e : type.getEnumConstants()) {
            if (e.name().equalsIgnoreCase(name)) {
                return e;
            }
        }

        return defaultValue;
    }
62340
public static DefaultValueFunction defaultValue(Function function, Object defaultValue) {

		Assert.notNull(function, "Function must not be 'null' for default value operation.");
		Assert.notNull(defaultValue, "DefaultValue must not be 'null'.");

		return new DefaultValueFunction(function, defaultValue);
	}
254313
@Override
    public final byte[] toBytes(Object o)
    {

        try
        {
            if (o != null)
            {
                if (o instanceof byte[])
                {
                    return (byte[]) o;
                }

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(o);
                oos.close();
                return baos.toByteArray();
            }
        }
        catch (IOException e)
        {
            log.error("IO exception, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
        return null;
    }
1170034
public static byte[] convertObjectToByteArray(Object o) throws IOException{
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(o);
		
		return bos.toByteArray();
	}
373816
@Nullable
  public static Byte parseByteObj (@Nullable final Object aObject)
  {
    return parseByteObj (aObject, DEFAULT_RADIX, null);
  }