I am developing two libraries for testing APIs. Library 1: Read XML response and convert it into java classes. (Getter and Setter methods) Library 2: Parse XML and set the data into setter methods of the java classes.
I have used java reflection to access the java classes which are created by library 1 and setting values into it. My setter method is storing array of objects. ( Multiple instances of same class).
However; when I am trying to retrieve the array objects I am getting null values. Because state of object is not maintaining and when I used "static" keyword, value of last object overwrites on previous object value.
<University>
<Student>
<Name>A</Name>
<Address>TX</Address>
<Subjects>
<Subject1>Maths</Subject1>
<Subject1>History</Subject1>
</Subjects>
</Student>
<Student>
<Name>B</Name>
<Address>CA</Address>
<Subjects>
<Subject1>EngMaths</Subject1>
<Subject1>Graphics</Subject1>
</Subjects>
</Student>
</University>
Here University Class has setter method like public setStudent(Student [] student) which will store array of Student class objects. Student Class has Name and Address values and it will also store the array of Subject class.
But in current scenario I am getting all null values in getter method and when I used static for all member variable , I am getting value of last object for all other object entries.
Can somebody tell me how to solve this problem?
Aucun commentaire:
Enregistrer un commentaire