Solution that I use is via reflection with exception catching.
This will work only for fields declared in this class not super!
@Override:
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(......);
sb.append(ExceptionHandler.ignoreLazy(this, "zone"));
return sb.toString();
}
public class ExceptionHandler:
public static String ignoreLazy(Object whom, String property)
{
try
{
Field field = whom.getClass().getDeclaredField(property);
field.setAccessible(true);
Object print = field.get(tkoMeSadrzi);
return print.toString();
}
catch (NoSuchFieldException e)
{
log.warn("DEVELOPER EXC ", e);
return "NoSuchFieldException: " + e.getMessage();
}
catch (Exception lazy)
{ //ignore
//log.debug("******* IGNORE LAZY : "+property);
return "lazy loaded!";
}
}
No comments:
Post a Comment