Exemple #1
0
 public static Object convertStringToObject(String value, Class<?> toType) {
   try {
     return org.apache.commons.beanutils.ConvertUtils.convert(value, toType);
   } catch (Exception e) {
     throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
   }
 }
Exemple #2
0
  public static List convertElementPropertyToList(Collection collection, String propertyName) {
    List list = new ArrayList();
    try {
      for (Iterator localIterator = collection.iterator(); localIterator.hasNext(); ) {
        Object obj = localIterator.next();
        list.add(PropertyUtils.getProperty(obj, propertyName));
      }
    } catch (Exception e) {
      throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return list;
  }
Exemple #3
0
  /**
   * 提取集合中的对象的属性(通过getter函数), 组合成List.
   *
   * @param collection 来源集合.
   * @param propertyName 要提取的属性名.
   */
  @SuppressWarnings("unchecked")
  public static List convertElementPropertyToList(
      final Collection collection, final String propertyName) {
    List list = new ArrayList();

    try {
      for (Object obj : collection) {
        list.add(PropertyUtils.getProperty(obj, propertyName));
      }
    } catch (Exception e) {
      throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return list;
  }