commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <>
Subject [Lang] Omitting a field in ToStringBuilder
Date Fri, 14 Feb 2003 01:30:42 GMT
Hello Commons-Lang,

I need to exclude a given field with
The Object I pass in is a javax.jms.Message which is a JMS abstract
interface which can be implemented with all sorts of fields. I know I just
do not want "messageText". 

My current implementation is nasty and does not feel right since I have to
use a ToStringStyle:

	private Object getMessageDescription(Message message) {
		class TempToStringStyle extends ToStringStyle {
			public void append(StringBuffer buffer, String
fieldName, Object value, Boolean fullDetail) {
				if ("messageText".equals(fieldName) ==
false) {
                    super.append(buffer, fieldName, value, fullDetail);
		return ToStringBuilder.reflectionToString(message, new
TempToStringStyle(), false);

I could imagine doing something like:

ToStringBuilder builder = new ToStringBuilder(message);
return builder.toString();

Any thoughts?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message