I looked for a clean CDI solution and not a WELD dependent one but so far nothing...
I need to test if every element of a list of objects that I get with @Inject
@Any
MyInterface
beans is a proxy, and when true
I need to get the real object to do introspection and get all the properties of the object.
My WELD implementation:
MyInterface interf = obj;
if (isProxy(interf )) {
interf = (Config) ((TargetInstanceProxy)interf ).getTargetInstance();
}
where isProxy
is so defined (CDI solution?):
public boolean isProxy(Object obj) {
try{
return Class.forName("org.jboss.weld.bean.proxy.ProxyObject").isInstance(obj);
} catch (Exception e) {
LOGGER.error("Unable to check if object is proxy", e);
}
return false;
}
Any suggestions /Indications. In the official documentation I found no mention of introspection (here)
And then I would like to get all the properties of the bean with something like this:
Arrays.stream(interf.getClass().getDeclaredFields()).forEach(
field -> extractStuff(...)
);
We use Wildfly and WELD but don't want to bind us to an implementation of CDI. Thanks in advance!
EDIT: The question is, more precisely: Do you know a clean CDI solution that WELD is already implementing with TargetInstanceProxy? Not if I need to go back to school or if I understand what I'm writing.. Thanks for taking time to help!