FieldUtils { private static Object getByGetter(Object object, Field field) throws RdfException { PropertyDescriptor descriptor = getDescriptor(field); try { return descriptor.getReadMethod().invoke(object); } catch (Throwable ex) { throw new RdfException( "Can't get value (by getter): {}", field.getName(), ex); } } private  FieldUtils(); static Object getValue(Object object, Field field); static void setValue(Object object, Field field, Object value);  }
@Test public void getByGetter() throws Exception { TestClass entity = new TestClass(); entity.setProtectedValue("value"); Field field = TestClass.class.getDeclaredField("protectedValue"); FieldUtils.getValue(entity, field); String actualValue = (String)FieldUtils.getValue(entity, field); Assert.assertEquals(entity.getProtectedValue(), actualValue); }