class BeanUtils {

    public static void mapToBean(Object bean, Map<String, Object> data, boolean ignoreNotExistingSetter) 
            throws InvocationTargetException, IllegalArgumentException {
        if (data == null || bean == null) {
            return;
        }
        Class clazz = bean.getClass();
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            try {
                Method mtd = getSetter(bean, entry.getKey());
                if (mtd == null) {
                    if (!ignoreNotExistingSetter) {
                        throw new IllegalArgumentException();
                    }
                    continue;
                }
                mtd.invoke(bean, entry.getValue());
            } catch (IllegalAccessException ex) {
            } 
        }
    }

}