I have an ArrayList of a java object with name say, "mylist". I am getting the name of the list(mylist) from database which comes as a String. I need to find the size of this list in JAVA and need to iterate over it.
Is there a way to do this?
Edit: To be more clear here, I have a class "Candidate"
class Candidate {
String firstName;
String lastName;
List<Education>educationRecords;
.....
}
class Education {
String school;
String degree;
.....
}
I need to populate Candidate object from a JSONObject whose structure is very different from Candidate object(so can't use Gson or jackson).
The simple fields like firstName, lastName, school and degree are stored in the database.
I fetch a Listfields and iterate over them to set the Candidate object. For setting firstName, lastName, I am using SpEL.
But, for fields like school and degree, it becomes complex as I would need to know the size of education records in JSONObject.
So, what I thought was while iterating over all fields if school field is present in Education class(using reflection), I would need to check if educationRecords is a of List type in Candidate class and then by some logic X(taking educationRecords as variable name) iterate over it.
It is the logic "X" I am missing.