@Test public void testConversionByteToString() { String result = (String) TypeConversionSupport.convert((byte) 42, String.class); assertNotNull(result); assertEquals("42", result); }
public static Object convert(Object value, Class<?> toClass) { assert value != null && toClass != null; if (value.getClass() == toClass) { return value; } Class<?> fromClass = value.getClass(); if (fromClass.isPrimitive()) { fromClass = convertPrimitiveTypeToWrapperType(fromClass); } if (toClass.isPrimitive()) { toClass = convertPrimitiveTypeToWrapperType(toClass); } Converter c = CONVERSION_MAP.get(new ConversionKey(fromClass, toClass)); if (c == null) { return null; } return c.convert(value); }
TypeConversionSupport { public static Object convert(Object value, Class<?> toClass) { assert value != null && toClass != null; if (value.getClass() == toClass) { return value; } Class<?> fromClass = value.getClass(); if (fromClass.isPrimitive()) { fromClass = convertPrimitiveTypeToWrapperType(fromClass); } if (toClass.isPrimitive()) { toClass = convertPrimitiveTypeToWrapperType(toClass); } Converter c = CONVERSION_MAP.get(new ConversionKey(fromClass, toClass)); if (c == null) { return null; } return c.convert(value); } }
TypeConversionSupport { public static Object convert(Object value, Class<?> toClass) { assert value != null && toClass != null; if (value.getClass() == toClass) { return value; } Class<?> fromClass = value.getClass(); if (fromClass.isPrimitive()) { fromClass = convertPrimitiveTypeToWrapperType(fromClass); } if (toClass.isPrimitive()) { toClass = convertPrimitiveTypeToWrapperType(toClass); } Converter c = CONVERSION_MAP.get(new ConversionKey(fromClass, toClass)); if (c == null) { return null; } return c.convert(value); } private  TypeConversionSupport(); }
TypeConversionSupport { public static Object convert(Object value, Class<?> toClass) { assert value != null && toClass != null; if (value.getClass() == toClass) { return value; } Class<?> fromClass = value.getClass(); if (fromClass.isPrimitive()) { fromClass = convertPrimitiveTypeToWrapperType(fromClass); } if (toClass.isPrimitive()) { toClass = convertPrimitiveTypeToWrapperType(toClass); } Converter c = CONVERSION_MAP.get(new ConversionKey(fromClass, toClass)); if (c == null) { return null; } return c.convert(value); } private  TypeConversionSupport(); static Object convert(Object value, Class<?> toClass); }
TypeConversionSupport { public static Object convert(Object value, Class<?> toClass) { assert value != null && toClass != null; if (value.getClass() == toClass) { return value; } Class<?> fromClass = value.getClass(); if (fromClass.isPrimitive()) { fromClass = convertPrimitiveTypeToWrapperType(fromClass); } if (toClass.isPrimitive()) { toClass = convertPrimitiveTypeToWrapperType(toClass); } Converter c = CONVERSION_MAP.get(new ConversionKey(fromClass, toClass)); if (c == null) { return null; } return c.convert(value); } private  TypeConversionSupport(); static Object convert(Object value, Class<?> toClass);  }