java - Javabean Introspector - what is in my List? -


i use code find out java list in given class:

beaninfo beaninfo = introspector.getbeaninfo(classx); propertydescriptor[] propertydescriptors = beaninfo .getpropertydescriptors();  (propertydescriptor pd : propertydescriptors) {     class<?> ptype = pd.getpropertytype();      if ((ptype+"").contains("java.util.list")) {         system.out.println("list class property: " + pd.getname() + ", type=" + ptype);      } } 

this output:

class property: value, type=interface java.util.list 

the question how find out type in list? example list defined in classx as:

@jsonproperty("value") private list<value> value = new arraylist<value>(); 

how can know list list of value objects? thanks.

you can not via property introspection, due type erasure. type class has no generic type parameter information (directly @ least; super-type relationships do). generic type declarations need able access java.lang.reflect.type (of class 1 implementation; ones generic parameters generictype).

there libraries allow resolve generic types, example java-classmate. give access resolved type information fields , methods, point need figure out logical bean properties. possible combine two, if want, use bean introspection finding methods, match resolved information java-classmate can offer.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -