public class BaseDto implements Serializable{
protected void appendAttributes(Object obj, StringBuffer buffer) {
if (obj == null) {
return;
}
try {
Class clazz = obj.getClass();
Field[] fields = clazz.getFields();
for (int i = 0; i < fields.length; i++) {
buffer.append(" | " + fields[i].getName());
try {
buffer.append(" [" + fields[i].get(obj) + "]");
} catch (Exception e) {
buffer.append(" [?]");
}
}
} catch (Exception e) {}
}
public String toString() {
StringBuffer result = new StringBuffer(getClass().getName());
result.append("@" + hashCode());
appendAttributes(this, result);
return result.toString();
}
}
Nenhum comentário:
Postar um comentário