class BeanUtils {

  public static Map<String, String> beanMap(Object bean, boolean sorted) {
    Map<String, String> map =
            sorted ? new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER)
                   : new HashMap<String, String>();

    for (Method method : bean.getClass().getMethods()) {
      if (method.getName().startsWith("get") && !method.getName().equals("getClass") && (method.getReturnType() != null)) {
        try {
          Object o = method.invoke(bean);
          String name = method.getName().substring(3);
          name = name.substring(0, 1).toLowerCase() + name.substring(1);
          map.put(name, o == null ? "null" : o.toString());
        } catch (Exception e) {
          // could not get property: ignore
        }
      }
    }
    return map;
  }

  private  BeanUtils();

}