@Test public void convertEmployeeFromListStringNull() { Employee e = Conversions.coerce(Employee.class, Lists.list("Rick", null)); boolean ok = e.name.equals("Rick") || die(); ok &= e.age == null || die(); }
public static <T> T coerce(Class<T> clz, Object value) { if (value != null) { if (clz == value.getClass()) { return (T) value; } } return coerce(TypeType.getType(clz), clz, value); }
Conversions { public static <T> T coerce(Class<T> clz, Object value) { if (value != null) { if (clz == value.getClass()) { return (T) value; } } return coerce(TypeType.getType(clz), clz, value); } }
Conversions { public static <T> T coerce(Class<T> clz, Object value) { if (value != null) { if (clz == value.getClass()) { return (T) value; } } return coerce(TypeType.getType(clz), clz, value); }  }
Conversions { public static <T> T coerce(Class<T> clz, Object value) { if (value != null) { if (clz == value.getClass()) { return (T) value; } } return coerce(TypeType.getType(clz), clz, value); }  static BigDecimal toBigDecimal(Object obj); static BigInteger toBigInteger(Object obj); static int toInt(Object obj); static int toInt(Object obj, int defaultValue); static byte toByte(Object obj); static byte toByte(Object obj, byte defaultByte); static short toShort(Object obj); static short toShort(Object obj, final short shortDefault); static char toChar(Object obj); static char toChar(Object obj, final char defaultChar); static long toLong(Object obj); static long toLongOrDie(Object obj); static long toLong(Object obj, final long longDefault); static Currency toCurrency(Object obj); static boolean toBoolean(Object value); static boolean toBoolean(Object obj, boolean defaultValue); static boolean toBooleanOrDie(Object obj); static double toDouble(Object obj); static float toFloat(Object obj); static T coerce(Class<T> clz, Object value); static T createFromArg(Class<T> clz, Object value); static T coerce(TypeType coerceTo, Class<T> clz, Object value); static T coerceWithFlag(Class<T> clz, boolean [] flag, Object value); static T coerceWithFlag(TypeType coerceTo, Class<T> clz, boolean [] flag, Object value); static TimeZone toTimeZone(boolean[] flag, Object value); static TimeZone toTimeZone(Object value); @SuppressWarnings("unchecked") static T coerceClassic(Class<T> clz, Object value); static T toEnumOld(Class<T> cls, String value); static T toEnum(Class<T> cls, String value); static T toEnum(Class<T> cls, String value, Enum defaultEnum); static T toEnum(Class<T> cls, int value); static T toEnumOrDie(Class<T> cls, int value); static T toEnum(Class<T> cls, Object value); @SuppressWarnings("unchecked") static T toPrimitiveArrayIfPossible(Class<T> clz, Object value); static double[] darray(Object value); static float[] farray(Object value); static long[] larray(Object value); static short[] sarray(Object value); static int[] iarray(Object value); static byte[] barray(Object value); static char[] carray(Object value); @SuppressWarnings("unchecked") static Iterator iterator(final Object value); static Iterator<T> iterator(Class<T> class1, final Object value); @SuppressWarnings("unchecked") static T toCollection(Class<T> clz, Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static List toList(Object value); static Collection toCollection(Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static Set toSet(Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static SortedSet toSortedSet(Object value); static Map<String, Object> toMap(Object value); static Number toWrapper(long l); static Number toWrapper(int i); static Object wrapAsObject(boolean i); static Object wrapAsObject(byte i); static Object wrapAsObject(short i); static Object wrapAsObject(int i); static Object wrapAsObject(long i); static Object wrapAsObject(double i); static Object wrapAsObject(float i); static Object toArrayGuessType(Collection<?> value); static T[] toArray(Class<T> componentType, Collection<T> collection); static V[] array(Class<V> type, final Collection<V> array); static Date toDate(Object object); static Calendar toCalendar(Date date); static Date toDate(Calendar c); static Date toDate(long value); static Date toDate(Long value); static Date toDate(String value); static Date toDateUS(String string); static Date toEuroDate(String string); static Collection<Object> createCollection(Class<?> type, int size); static Map<?, ?> createMap(Class<?> type, int size); static List<TO> mapFilterNulls(Function<FROM, TO> converter,
                                                     Collection<FROM> fromCollection); static Object unifyListOrArray(Object o); static Object unifyListOrArray(Object o, List list); static Object unifyList(List list); static Object unifyList(Object o, List list); static Comparable comparable(Object comparable); Number coerceNumber(Object inputArgument, Class<?> paraType); static int lengthOf(Object obj); static int len(Object obj); static Class<?> toClass(Object value); static Class<?> toClass(String str); static String toString(Object obj, String defaultValue); static String toString(Object obj); }
Conversions { public static <T> T coerce(Class<T> clz, Object value) { if (value != null) { if (clz == value.getClass()) { return (T) value; } } return coerce(TypeType.getType(clz), clz, value); }  static BigDecimal toBigDecimal(Object obj); static BigInteger toBigInteger(Object obj); static int toInt(Object obj); static int toInt(Object obj, int defaultValue); static byte toByte(Object obj); static byte toByte(Object obj, byte defaultByte); static short toShort(Object obj); static short toShort(Object obj, final short shortDefault); static char toChar(Object obj); static char toChar(Object obj, final char defaultChar); static long toLong(Object obj); static long toLongOrDie(Object obj); static long toLong(Object obj, final long longDefault); static Currency toCurrency(Object obj); static boolean toBoolean(Object value); static boolean toBoolean(Object obj, boolean defaultValue); static boolean toBooleanOrDie(Object obj); static double toDouble(Object obj); static float toFloat(Object obj); static T coerce(Class<T> clz, Object value); static T createFromArg(Class<T> clz, Object value); static T coerce(TypeType coerceTo, Class<T> clz, Object value); static T coerceWithFlag(Class<T> clz, boolean [] flag, Object value); static T coerceWithFlag(TypeType coerceTo, Class<T> clz, boolean [] flag, Object value); static TimeZone toTimeZone(boolean[] flag, Object value); static TimeZone toTimeZone(Object value); @SuppressWarnings("unchecked") static T coerceClassic(Class<T> clz, Object value); static T toEnumOld(Class<T> cls, String value); static T toEnum(Class<T> cls, String value); static T toEnum(Class<T> cls, String value, Enum defaultEnum); static T toEnum(Class<T> cls, int value); static T toEnumOrDie(Class<T> cls, int value); static T toEnum(Class<T> cls, Object value); @SuppressWarnings("unchecked") static T toPrimitiveArrayIfPossible(Class<T> clz, Object value); static double[] darray(Object value); static float[] farray(Object value); static long[] larray(Object value); static short[] sarray(Object value); static int[] iarray(Object value); static byte[] barray(Object value); static char[] carray(Object value); @SuppressWarnings("unchecked") static Iterator iterator(final Object value); static Iterator<T> iterator(Class<T> class1, final Object value); @SuppressWarnings("unchecked") static T toCollection(Class<T> clz, Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static List toList(Object value); static Collection toCollection(Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static Set toSet(Object value); @SuppressWarnings({"rawtypes", "unchecked"}) static SortedSet toSortedSet(Object value); static Map<String, Object> toMap(Object value); static Number toWrapper(long l); static Number toWrapper(int i); static Object wrapAsObject(boolean i); static Object wrapAsObject(byte i); static Object wrapAsObject(short i); static Object wrapAsObject(int i); static Object wrapAsObject(long i); static Object wrapAsObject(double i); static Object wrapAsObject(float i); static Object toArrayGuessType(Collection<?> value); static T[] toArray(Class<T> componentType, Collection<T> collection); static V[] array(Class<V> type, final Collection<V> array); static Date toDate(Object object); static Calendar toCalendar(Date date); static Date toDate(Calendar c); static Date toDate(long value); static Date toDate(Long value); static Date toDate(String value); static Date toDateUS(String string); static Date toEuroDate(String string); static Collection<Object> createCollection(Class<?> type, int size); static Map<?, ?> createMap(Class<?> type, int size); static List<TO> mapFilterNulls(Function<FROM, TO> converter,
                                                     Collection<FROM> fromCollection); static Object unifyListOrArray(Object o); static Object unifyListOrArray(Object o, List list); static Object unifyList(List list); static Object unifyList(Object o, List list); static Comparable comparable(Object comparable); Number coerceNumber(Object inputArgument, Class<?> paraType); static int lengthOf(Object obj); static int len(Object obj); static Class<?> toClass(Object value); static Class<?> toClass(String str); static String toString(Object obj, String defaultValue); static String toString(Object obj);  }