java - Convert Class Object to Human Readable String -


is there way in can automatically convert custom class object human readable string?

e.g. consider following class:

class person {     string name;     int salary;     ... }  person p = new person(); p.setname("tony"); p.setsalary(1000); 

i need like:

person: name="tony", salary=1000 

importing commons lang use tostringbuilder

check method reflectiontostring(java.lang.object), create automatically representation expecting.

this code:

person p = new person(); p.setname("tony"); p.setsalary(1000);  system.out.println(tostringbuilder.reflectiontostring(p)); 

results string:

person@64578ceb[name=tony,salary=1000] 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -