MyLangUtils { public static void trimRootLevelStringFields(Object bean) { if (bean == null) { return; } Field[] fields = bean.getClass().getDeclaredFields(); if (fields == null) { return; } for (Field f : fields) { if (f.getType().isPrimitive()) { continue; } if (f.getType().equals(String.class)) { try { f.setAccessible(true); String value = (String) f.get(bean); f.set(bean, StringUtils.trimToNull(value)); } catch (IllegalAccessException e) { } } } }  static Calendar newCalendar(long milis); static void trimRootLevelStringFields(Object bean); static void copyProperties(Object dest, Object src); static DESTIN copyPropertiesToNewObject(
			Class<DESTIN> destClass, Object src); static List<DESTIN> copyPropertiesToNewCollections(
			Class<DESTIN> destClass, Collection<?> srcCollection); static byte[] toUtf8Bytes(String str);  }
@Test public void testTrimStringProps() throws Exception { BeanToTrim btt = new BeanToTrim(); MyLangUtils.trimRootLevelStringFields(btt); System.out.println(btt); Assert.assertEquals("withSpace", btt.withSpace); Assert.assertNull(btt.allBlank); Assert.assertEquals(" subName ", btt.sb.subName); }