Is there any way in which I can automatically convert a Custom Class Object into a human readable string?
e.g. consider the following class:
class Person {
String Name;
int Salary;
...
}
Person p = new Person();
p.setName("Tony");
p.setSalary(1000);
I need to get something like:
Person: Name="Tony", Salary=1000
Importing Commons Lang you could use ToStringBuilder
Check method
reflectionToString(java.lang.Object), this will create automatically the representation you are expecting.This code:
results this string: