ParameterBeanMapperUtils { public static <T> T mapParametersToBean(Map<String, Object> parameters, Class<T> cls) { try { T bean = cls.newInstance(); BeanUtilsBean beanUtils = new BeanUtilsBean(); beanUtils.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); beanUtils.populate(bean, parameters); return bean; } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new IllegalArgumentException("Error mapping parameters to class of type " + cls.getName(), e); } } private  ParameterBeanMapperUtils(); static T mapParametersToBean(Map<String, Object> parameters, Class<T> cls);  }
@Test void mapParametersToBean() { Map<String, Object> parameters = new HashMap<>(); parameters.put("stringProperty", "value1"); parameters.put("intProperty", 2); parameters.put("extraProperty", "extra"); parameters.put("nestedBean.booleanProperty", true); TestBean testBean = ParameterBeanMapperUtils.mapParametersToBean(parameters, TestBean.class); assertThat(testBean.getStringProperty()).isEqualTo("value1"); assertThat(testBean.getIntProperty()).isEqualTo(2); assertThat(testBean.getUnusedProperty()).isNull(); assertThat(testBean.getNestedBean().isBooleanProperty()).isEqualTo(true); }