@SuppressWarnings("unchecked") @Test public void simpleListConversion() { final List<CValue> list = new ArrayList<CValue>(); list.add(new CPrimitive("hei")); final List<String> convertedList = (List<String>) ValueConverterRegistry.convert(String.class, String.class, new CArray(list)); Assert.assertNotNull(convertedList); Assert.assertTrue(convertedList.size() == 1); }
@SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } }
ValueConverterRegistry { @SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } } }
ValueConverterRegistry { @SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } }  }
ValueConverterRegistry { @SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } }  static void registerCustomConverter(Class<?> converterFor, ValueConverter<?> converter); @SuppressWarnings("unchecked") static Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value); @SuppressWarnings("unchecked") static List<T> convertList(Class<T> clazz, CArray list); @SuppressWarnings("unchecked") static T convertPrimitive(Class<T> clazz, CPrimitive value); @SuppressWarnings("unchecked") static Map<K, V> convertMap(Class<K> keyClazz, Class<V> valueClazz, CObject value); static T convertEnum(Class<T> clazz, String value); }
ValueConverterRegistry { @SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } }  static void registerCustomConverter(Class<?> converterFor, ValueConverter<?> converter); @SuppressWarnings("unchecked") static Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value); @SuppressWarnings("unchecked") static List<T> convertList(Class<T> clazz, CArray list); @SuppressWarnings("unchecked") static T convertPrimitive(Class<T> clazz, CPrimitive value); @SuppressWarnings("unchecked") static Map<K, V> convertMap(Class<K> keyClazz, Class<V> valueClazz, CObject value); static T convertEnum(Class<T> clazz, String value);  }