For example, if I wanted to register the Converter for all instances of java.util.Map, is there a way to do this:
new BeanUtilsBean().getConvertUtils().register(new MyConverter(), Map.class);
where is the method MyConverter#convert() called for any instance of the Map (for example, HashMap)?
At the heart of this is that I use BeanUtils to populate various beans from the database. Some of their properties are enumerations that implement a specific interface, and a custom routine is required to set their values. I was hoping to register one converter class for all implementations of the interface in question, but could not find a way to do this, so he had to do it on the fly by checking the class of each property in beans and registering my converter class if they were instances of this interface:
BeanUtilsBean b = new BeanUtilsBean(); Class< ? > propertyType = pu.getPropertyType(this, setterName); if (isImplementationOfMyInterface(propertyType)) { b.getConvertUtils().register(new MyConverter(), propertyType); } b.setProperty(this, setterName, value);
It seems pretty nasty, and I'm sure there should be a better way to do this?
source share