DistributedResourceManager extends Configured { public static void setFieldValue(Field field, Object bean, Object value) throws IllegalAccessException { field.setAccessible(true); SimpleTypeConverter converter = new SimpleTypeConverter(); try { value = converter.convertIfNecessary(value, field.getType()); } catch (ConversionNotSupportedException e) { } field.set(bean, value); } protected  DistributedResourceManager(Job job); void registerResource(String key, Object value); @SuppressWarnings("unchecked") static void initializeResources(Object bean, Configuration config); static void setFieldValue(Field field, Object bean, Object value); static final String VALUE_SEP; static final String CONFIGKEYBASE_RESOURCE; }
@Test public void testSetFieldValue() { Object bean = new TargetBean(); Map<String, String> fieldVals = new HashMap<>(); fieldVals.put("b","true"); fieldVals.put("c","a"); fieldVals.put("i","475"); fieldVals.put("s","25"); fieldVals.put("f","999.99"); fieldVals.put("d","1234567.0"); fieldVals.put("l","123456789"); fieldVals.put("B","false"); fieldVals.put("C","Z"); fieldVals.put("I","4750"); fieldVals.put("S","50"); fieldVals.put("F","1999.99"); fieldVals.put("D","1234567.0"); fieldVals.put("L","1234567890"); try { for (Entry<String,String> e : fieldVals.entrySet()) { Field field = bean.getClass().getDeclaredField(e.getKey()); String value = e.getValue(); DistributedResourceManager.setFieldValue(field, bean, value); assertThat(field.get(bean).toString(), equalTo(value)); } } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { fail(e.getMessage()); } }