Here you can find the source of setFieldValue(Map
public static Object setFieldValue(Map<String, Object> map, Class<?> cls) throws Exception
//package com.java2s; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Map; public class Main { public static Object setFieldValue(Map<String, Object> map, Class<?> cls) throws Exception { Field[] fields = cls.getDeclaredFields(); Object obj = cls.newInstance(); for (Field field : fields) { Class<?> clsType = field.getType(); String name = field.getName(); String strSet = "set" + name.substring(0, 1).toUpperCase() + name.substring(1, name.length()); Method methodSet = cls.getDeclaredMethod(strSet, clsType); if (map.containsKey(name)) { Object objValue = map.get(name); methodSet.invoke(obj, objValue); }/*from www . j a va 2s. c om*/ } return obj; } }