Simplified solution:
@Override public String toString() { return ReflectionToStringBuilder.toStringExclude(this, "data"); }
If DefaultToStringStyle does not meet the needs of your application, be sure to call
ReflectionToStringBuilder.setDefaultStyle(style);
when you start the application.
If you have more fields to exclude, just add them after or before the "data"
@Override public String toString() { return ReflectionToStringBuilder.toStringExclude(this, "fieldX","data", "fieldY"); }
Olivier
source share