List of utility methods to do Reflection Field Value Set
void | setFieldValue(final Object bean, final Field field, final Object value) set Field Value if (!field.isAccessible()) { field.setAccessible(true); try { field.set(bean, value); } catch (final IllegalAccessException e) { throw new IOException("Cannot set " + field.getName() + ": " + e.getMessage(), e); } catch (final IllegalArgumentException e) { ... |
void | setFieldValue(final Object obj, final String fieldName, final Object value) set Field Value getSetField(obj, fieldName, false, value); |
void | setFieldValue(final Object object, final String field, final Object value) Applies specified value to object field. final Field actualField = getField(object.getClass(), field);
actualField.setAccessible(true);
actualField.set(object, value);
|
void | setFieldValue(final Object object, final String fieldName, final Object value) set Field Value Field field = getDeclaredField(object.getClass(), fieldName); makeAccessible(field); field.set(object, value); |
void | setFieldValue(final Object object, final String fieldName, final Object value) set Field Value @SuppressWarnings("rawtypes") Class clazz = object.getClass(); try { getAccessibleField(clazz, fieldName).set(object, value); } catch (Exception e) { throw new RuntimeException(e); |
void | setFieldValue(final Object object, final String fieldName, final Object value) set Field Value Field field = getDeclaredField(object, fieldName); if (field == null) throw new IllegalArgumentException( "Could not find field [" + fieldName + "] on target [" + object + "]"); makeAccessible(field); try { field.set(object, value); } catch (IllegalAccessException e) { ... |
Object | setFieldValue(Map set Field Value 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)) { ... |
void | setFieldValue(Object bean, Field field, Object value) This method is used to set the value of a field of a model object to the specified value. Class<?> targetType = field.getType(); Class<?> sourceType = value.getClass(); if (targetType.isAssignableFrom(sourceType)) { field.setAccessible(true); field.set(bean, value); } else { throw new IllegalArgumentException(String.format( "Attempt to set property %s of type %s from a " + "value of type %s, types are not assignable.", ... |
void | setFieldValue(Object bean, Field field, Object value) set Field Value Method method = null; method = getSetMethod(bean.getClass(), field); if (method == null) { throw new NoSuchMethodException("can not find the set method"); } else { method.invoke(bean, new Object[] { value }); |
void | setFieldValue(Object bean, String field, Object value) Used to set value of specified field irrespective of the field modifier try { Field fieldObj = bean.getClass().getDeclaredField(field); fieldObj.setAccessible(true); fieldObj.set(bean, value); } catch (Exception ex) { throw new IllegalStateException("An error occurred while seting field value - " + field, ex); |