public String idFromValue(Object value) { String str = value.getClass().getName(); /* 25-Jan-2009, tatus: There are some internal classes that * we can not access as is. We need better mechanism; for * now this has to do... */ if (str.startsWith("java.util")) { /* Enum sets and maps are problematic since we MUST know * type of contained enums, to be able to deserialize. * In addition, EnumSet is not a concrete type either */ if (value instanceof EnumSet<?>) { // Regular- and JumboEnumSet... Class<?> enumClass = ClassUtil.findEnumType((EnumSet<?>) value); str = TypeFactory.collectionType(EnumSet.class, enumClass).toCanonical(); } else if (value instanceof EnumMap<?, ?>) { Class<?> enumClass = ClassUtil.findEnumType((EnumMap<?, ?>) value); Class<?> valueClass = Object.class; str = TypeFactory.mapType(EnumMap.class, enumClass, valueClass).toCanonical(); } else if (str.startsWith("java.util.Arrays$") && str.indexOf("List") >= 0) { /* 17-Feb-2010, tatus: Another such case: result of * Arrays.asList() is named like so in Sun JDK... * Let's just plain old ArrayList in its place * NOTE: chances are there are plenty of similar cases * for other wrappers... (immutable, singleton, synced etc) */ str = "java.util.ArrayList"; } } return str; }
public static <T> List<T> toTList(String jsonString, Class<T> clazz) { try { return objMapperLocal .get() .readValue(jsonString, TypeFactory.collectionType(List.class, clazz)); } catch (Exception e) { e.printStackTrace(); } return null; }