I am while using Apache BeanUtils setProperty approach to import data from an Stand out file inside a generic manner. Provided the parser a listing of "colum title" and "property title" pairs and so the parser sets the qualities with setProperty( ..., "property title", ...) for that Stand out fields that complement "column title". It's working nice however I am getting an issue, I've got a property that's setted by having an addXXX() method and that i cannot change that class. How do i set this property without altering these kinds or even the parser? Is it feasible? Can One make something similar to a wrapper with DynaClass, PropertyUtils or MethodUtils then when setting that property it calls the addXX method?


You are able to write a decorator bean class which will cover your class and supply a setXXX() method assigning to addXXX() from the wrapped bean. You may also do this via dynamic proxy with assistance of cglib or other bytecode instrumentation library.

If you would rather go the DynaClass way, have a look at WrapDynaClass like a beginning point. You will need to extend it to supply custom PropertyDescriptor for the method. I would not do that, though, for 2 reasons - first, addXXX() semantics is probably not the same as setXXX() and next, the entire DynaClass/DynaBean internal API is a little untidy whereas writing your personal decorator class is extremely straightforward.