@Test public void testObjectPrimitives() { MyObjectPrimitiveBean bean = new MyObjectPrimitiveBean(); assertTrue(SimpleBeanUtil.callSetter(bean, "setLongParam", "1")); assertTrue(SimpleBeanUtil.callSetter(bean, "setDoubleParam", "1")); assertTrue(SimpleBeanUtil.callSetter(bean, "setStringParam", "1")); assertTrue(SimpleBeanUtil.callSetter(bean, "setBooleanParam", "yes")); assertTrue(SimpleBeanUtil.callSetter(bean, "setIntParam", "1")); assertTrue(SimpleBeanUtil.callSetter(bean, "setFloatParam", "1")); assertFalse(SimpleBeanUtil.callSetter(bean, "blah blah blah", "1")); assertFalse(SimpleBeanUtil.callSetter(bean, "setMyObject", "1")); assertFalse(SimpleBeanUtil.callSetter(bean, "setMultiParam", "1")); assertEquals(Long.valueOf(1L), bean.getLongParam()); assertEquals(Double.parseDouble("1"), bean.getDoubleParam(), 0.1); assertEquals("1", bean.getStringParam()); assertEquals(true, bean.getBooleanParam()); assertEquals(Integer.valueOf(1), bean.getIntParam()); assertEquals(Float.parseFloat("1"), bean.getFloatParam(), 0.1); }
public static boolean callSetter(Object obj, String methodName, String value) { boolean result = false; try { Method m = getSetterMethod(obj.getClass(), methodName); Object param = OBJECTIFIERS.get(m.getParameterTypes()[0]).objectify(value); m.invoke(obj, param); result = true; } catch (NullPointerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return result; }
SimpleBeanUtil { public static boolean callSetter(Object obj, String methodName, String value) { boolean result = false; try { Method m = getSetterMethod(obj.getClass(), methodName); Object param = OBJECTIFIERS.get(m.getParameterTypes()[0]).objectify(value); m.invoke(obj, param); result = true; } catch (NullPointerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return result; } }
SimpleBeanUtil { public static boolean callSetter(Object obj, String methodName, String value) { boolean result = false; try { Method m = getSetterMethod(obj.getClass(), methodName); Object param = OBJECTIFIERS.get(m.getParameterTypes()[0]).objectify(value); m.invoke(obj, param); result = true; } catch (NullPointerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return result; }  }
SimpleBeanUtil { public static boolean callSetter(Object obj, String methodName, String value) { boolean result = false; try { Method m = getSetterMethod(obj.getClass(), methodName); Object param = OBJECTIFIERS.get(m.getParameterTypes()[0]).objectify(value); m.invoke(obj, param); result = true; } catch (NullPointerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return result; }  static boolean callSetter(Object obj, String methodName, String value); }
SimpleBeanUtil { public static boolean callSetter(Object obj, String methodName, String value) { boolean result = false; try { Method m = getSetterMethod(obj.getClass(), methodName); Object param = OBJECTIFIERS.get(m.getParameterTypes()[0]).objectify(value); m.invoke(obj, param); result = true; } catch (NullPointerException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } return result; }  static boolean callSetter(Object obj, String methodName, String value);  }