@Test public void testToObject() { Map<String, Object> params = new HashMap<>(); params.put("name", "name"); params.put("age", 25); A a = new A(); MapUtil.toObject(params, a); assertEquals(a.getName(), "name"); assertEquals(a.getAge(), 25); }
public static void toObject(Map<String, Object> source, Object target, String... ignoreProperties) { PropertyDescriptor[] ts = ReflectUtil.getPropertyDescriptors(target); List<String> ignoreList = (ignoreProperties != null && ignoreProperties.length > 0) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor t : ts) { String name = t.getName(); if (ignoreList == null || !ignoreList.contains(name)) { Object value; if (null != source && (value = source.get(name)) != null) { ReflectUtil.setValueByField(target, name, value); } } } }
MapUtil { public static void toObject(Map<String, Object> source, Object target, String... ignoreProperties) { PropertyDescriptor[] ts = ReflectUtil.getPropertyDescriptors(target); List<String> ignoreList = (ignoreProperties != null && ignoreProperties.length > 0) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor t : ts) { String name = t.getName(); if (ignoreList == null || !ignoreList.contains(name)) { Object value; if (null != source && (value = source.get(name)) != null) { ReflectUtil.setValueByField(target, name, value); } } } } }
MapUtil { public static void toObject(Map<String, Object> source, Object target, String... ignoreProperties) { PropertyDescriptor[] ts = ReflectUtil.getPropertyDescriptors(target); List<String> ignoreList = (ignoreProperties != null && ignoreProperties.length > 0) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor t : ts) { String name = t.getName(); if (ignoreList == null || !ignoreList.contains(name)) { Object value; if (null != source && (value = source.get(name)) != null) { ReflectUtil.setValueByField(target, name, value); } } } }  }
MapUtil { public static void toObject(Map<String, Object> source, Object target, String... ignoreProperties) { PropertyDescriptor[] ts = ReflectUtil.getPropertyDescriptors(target); List<String> ignoreList = (ignoreProperties != null && ignoreProperties.length > 0) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor t : ts) { String name = t.getName(); if (ignoreList == null || !ignoreList.contains(name)) { Object value; if (null != source && (value = source.get(name)) != null) { ReflectUtil.setValueByField(target, name, value); } } } }  static MapPlain<K, V> build(); static MapPlain<K, V> build(int cap); static Map<String, Object> toMap(Object o, Map<String, String> map, String... ignoreProperties); static Map<String, Object> toMap(Object o, String... ignoreProperties); static void toObject(Map<String, Object> source, Object target, String... ignoreProperties); static List<Map<String, Object>> mapConvertToList(Map<K, V> map); static List<Map<String, Object>> mapConvertToList(Map<K, V> map, Object defaultValue); }
MapUtil { public static void toObject(Map<String, Object> source, Object target, String... ignoreProperties) { PropertyDescriptor[] ts = ReflectUtil.getPropertyDescriptors(target); List<String> ignoreList = (ignoreProperties != null && ignoreProperties.length > 0) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor t : ts) { String name = t.getName(); if (ignoreList == null || !ignoreList.contains(name)) { Object value; if (null != source && (value = source.get(name)) != null) { ReflectUtil.setValueByField(target, name, value); } } } }  static MapPlain<K, V> build(); static MapPlain<K, V> build(int cap); static Map<String, Object> toMap(Object o, Map<String, String> map, String... ignoreProperties); static Map<String, Object> toMap(Object o, String... ignoreProperties); static void toObject(Map<String, Object> source, Object target, String... ignoreProperties); static List<Map<String, Object>> mapConvertToList(Map<K, V> map); static List<Map<String, Object>> mapConvertToList(Map<K, V> map, Object defaultValue);  }