jeudi 19 août 2021

Recursively traverse an object instance (that has heavily nested custom objects) using java reflection APIs

I am looking a library or code snippet, that helps me Recursively traverse an object instance (that has heavily nested custom objects) using java reflection APIs.

NOTE :- Im looking for code snippet that traverses an object rather than a class footprint.

Example

Student
{
int age;
String name;
Double weight;
}

Student.class —> This is class footprint

Student stu = Student.builder.age(23).weight(46).build();

stu -> This is object

Now applying reflection on Student.class [class footprint] is different from stu [object instance] So, i am looking for applying reflection and recursively traverse all the nodes of my object instance. While traverse, i want to check what all fields have got null/non-null and accordingly apply some logic on top of it, to full-fill my use case.

TIA.





Aucun commentaire:

Enregistrer un commentaire