### Question:
PropertyAccessorHelper { public static String getString(Object from, Field field) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field); Object object = getObject(from, field); return object != null ? accessor.toString(object) : null; }  static void set(Object target, Field field, byte[] bytes); static void set(Object target, Field field, String fieldVal); static void set(Object target, Field field, Object value); static Object getObject(Object from, Field field); static Object getObjectCopy(Object from, Field field); static String getString(Object from, Field field); static byte[] get(Object from, Field field); static Object getId(Object entity, EntityMetadata metadata); static void setId(Object entity, EntityMetadata metadata, Object rowKey); static void setId(Object entity, EntityMetadata metadata, byte[] rowKey); @SuppressWarnings("null") // TODO: Too much code, improve this, possibly by breaking it static final Object getObject(Object obj, String fieldName); static Class<?> getGenericClass(Field collectionField); static List<Class<?>> getGenericClasses(Field collectionField); static Field[] getDeclaredFields(Field relationalField); static final boolean isCollection(Class<?> clazz); static final Object getObject(Class<?> clazz); static final byte[] toBytes(Object o, Field f); static final byte[] toBytes(Object o, Class c); static Object fromSourceToTargetClass(Class<?> targetClass, Class<?> sourceClass, Object o); static Object fromDate(Class<?> targetClass, Class<?> sourceClass, Object o); static byte[] getBytes(Object o); static String getString(Object o); static Object getObject(Class clazz, byte[] b); static final Collection getCollectionInstance(Field collectionField);  }### Answer:
@Test public void testGetStringObjectField() { PersonnelDTO person = new PersonnelDTO("1", "Amresh", "Singh"); try { String id = PropertyAccessorHelper.getString(person, person.getClass().getDeclaredField("personId")); String fn = PropertyAccessorHelper.getString(person, person.getClass().getDeclaredField("firstName")); String ln = PropertyAccessorHelper.getString(person, person.getClass().getDeclaredField("lastName")); Assert.assertEquals("1", id); Assert.assertEquals("Amresh", fn); Assert.assertEquals("Singh", ln); } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchFieldException e) { Assert.fail(e.getMessage()); } }