mardi 14 août 2018

Print any complex java object graph

I have a requirement where i want to get all the keys and there correspondence values in a java object as a string Eg:

    Student s1 = new Student();
    s1.setsAge(10);
    s1.setsName("aaaa");

    Student s2 = new Student();
    s2.setsAge(15);
    s2.setsName("bbbb");

    List<Student> stu = new ArrayList<>();
    stu.add(s1);
    stu.add(s2);

    School sc1 = new School();
    sc1.setName(null);
    sc1.setBuilding("building");
    sc1.setStudent(stu);

Eg:

String printMethod(sc1)

is there any library to do this or is there any way using reflections. i cannot use the toString() method.





Aucun commentaire:

Enregistrer un commentaire