Sunday 15 June 2014

class - Java reflection querying annotations by type -



class - Java reflection querying annotations by type -

i'm trying query annotations class using code:

for (final annotation annotation : annotations) system.out.println(annotation); final jsonschema[] schemas = clazz.getannotationsbytype(jsonschema.class); if (schemas.length == 0) { throw new illegalargumentexception("no jsonschema annotation found."); }

if arrive here via unit test past schemas.length test. if via maven plugin passes url of class urlclassloader().loadclass() throws illegalargumentexception. however, prints out:

@mypackage.jsonschema()

i.e. annotation appears there if loop through results of getannotations() isn't found getannotationsbytype. causing this?

edit: if seek looping through , comparing canonical names casting jsonschema won't allow me appears com.sun.proxy not instanceof jsonschema.

edit: it's because they're in different class loaders, i'm sure. quite how prepare that...

got it.

i passing array of urls classes load new urlclassloader(). adding sec parameter of thread.currentthread().getcontextclassloader() constructor seems load them same classloader , works expected.

java class classloader maven-plugin

No comments:

Post a Comment