Код: Выделить всё
public static T convert(Map values, Class beanClass) throws Exception {
T instance = beanClass.getConstructor().newInstance();
Map fieldMap = Stream.of(beanClass.getDeclaredFields())
.peek(field -> field.setAccessible(true))
.collect(Collectors.toMap(Field::getName, field -> field));
values.forEach((key, value) -> {
try {
fieldMap.get(key).set(instance, value);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
});
return instance;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... reflection