Here you can find the source of setFieldValue(Object obj, String fieldName, String fieldValue)
public static void setFieldValue(Object obj, String fieldName, String fieldValue) throws IllegalArgumentException, IllegalAccessException
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setFieldValue(Object obj, String fieldName, String fieldValue) throws IllegalArgumentException, IllegalAccessException { Field field = getField(obj.getClass(), fieldName); if (field != null) { field.setAccessible(true);/*from w w w.j a v a 2 s. co m*/ field.set(obj, fieldValue); } } public static <T> Field getField(Class<T> clazz, String fieldName) { try { Field field = clazz.getDeclaredField(fieldName); if (field == null) { field = clazz.getSuperclass().getDeclaredField(fieldName); } return field; } catch (Exception e) { e.printStackTrace(); return null; } } }