JsonHelper { @SuppressWarnings({ "rawtypes", "unchecked" }) public static final Object toJsonObject(Object object) { if (object == null) { return null; } else if (object instanceof DLFilterBean) { return ((DLFilterBean) object).toJson(); } else if (isBasicType(object)) { return object; } else if (object.getClass().isEnum()) { return object.toString(); } else if (Date.class.isAssignableFrom(object.getClass())) { return ((Date) object).getTime(); } else if (Collection.class.isAssignableFrom(object.getClass())) { Collection<?> collection = (Collection<?>) object; List serializableCollection = new ArrayList(); for (Object value : collection) { serializableCollection.add(toJsonObject(value)); } return serializableCollection; } else { throw new IllegalArgumentException("Unserializable filter type: " + object.getClass()); } }  @SuppressWarnings({ "rawtypes", "unchecked" }) static final Object toJsonObject(Object object); @SuppressWarnings({ "unchecked", "rawtypes" }) static final Object fromJsonObject(Object object, String type); @SuppressWarnings({ "unchecked", "rawtypes" }) static Object restoreType(Object object, Class<?> typeClazz); static String getType(Object value); static boolean isBasicType(Object object);  }
@Test(expected = IllegalArgumentException.class) public void testWrongBean() { WrongClz value = new WrongClz(); JsonHelper.toJsonObject(value); }