>  from:    Gary Gregory <[EMAIL PROTECTED]>
> I need to exclude a given field with
> ToStringBuilder.reflectionToString(Object). 
> 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);
> builder.remove(messageText);
> return builder.toString();

An interesting requirement. This last solution is incomplete as it doesn't use 
reflectionToString. A ToStringStyle can be passed in to reflectionToString though, so 
your basic solution seems sound.

Perhaps what is needed is a ToStringStyle decorator (like the collections unmodifiable 
and synchronized decorators) that blocks certain field names? Essentially this would 
add your temporary tostringstyle to [lang].

Stephen




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to