I have been trying to determine the type of a field in a class. I've seen all the introspection methods but haven't quite figured out how to do it. This is going to be used to generate xml/json from a java class. I've looked at a number of the questions here but haven't found exactly what I need.
Example:
class Person {
public final String name;
public final List<Person> children;
}
When I marshall this object, I need to know that the chidren
field is a list of objects of type Person
, so I can marshall it properly.
I had tried
for (Field field : Person.class.getDeclaredFields()) {
System.out.format("Type: %s%n", field.getType());
}
But this will only tell me that it's a List
, not a List
of Person
s
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…