ReplaceValueSetter implements ValueSetter { @Override public void setValue(BeanWrapper bean, String propertyName) { Object value = bean.getPropertyValue(propertyName); if (value == null) { return; } String stringValue = value.toString(); String updatedValue = stringValue.replaceAll(matchRegex, replacementValue); if (!stringValue.equals(updatedValue)) { if (bean.getPropertyType(propertyName) == AgencyAndId.class) { AgencyAndId aid = (AgencyAndId)bean.getPropertyValue(propertyName); aid.setId(updatedValue); bean.setPropertyValue(propertyName, aid); } else { bean.setPropertyValue(propertyName, updatedValue); } } } ReplaceValueSetter(String matchRegex, String replacementValue); @Override void setValue(BeanWrapper bean, String propertyName);  }
@Test public void test() { ReplaceValueSetter setter = new ReplaceValueSetter("cats", "dogs"); Stop stop = new Stop(); stop.setName("I like cats."); setter.setValue(BeanWrapperFactory.wrap(stop), "name"); assertEquals("I like dogs.", stop.getName()); }