I am using legacy bean classes for my project. Here, some superclasses will be empty, and the subclass may have fields, and some of the subclasses will be empty, and the superclass may have fields.
My requirement is to get all private / public fields from the Sub class, and also get all public / protected fields from the Super class.
Below I tried to achieve it. But I could not satisfy my requirements. Please provide some suggestion to achieve this.
Field fields [] = obj.getClass().getSuperclass().getDeclaredFields();
If I use the code above, I can only get Superclass fields
Field fields [] = obj.getClass().getFields();
If I use the code above, I can get all the fields from the Sub class and super class fields
Field fields [] = obj.getClass().getDeclaredFields();
If I use the code above, I can get the Sub class public and private all fields.
source share