commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Caswell <steven.casw...@gmail.com>
Subject Re: [lang] Using ReflectionToStringBuilder and excluding secure fields
Date Sat, 06 Aug 2005 22:28:03 GMT
+1

I've thought about something similar, just never did anything about
it. I like the idea of being able to exclude some fields from the
string build.

On 8/4/05, Gary Gregory <ggregory@seagullsoftware.com> wrote:
> Hello:
> 
> Right now, I use the code below to exclude password fields from output.
> 
>     /**
>      * Builds a String for a toString method excluding the given field
> name.
>      *
>      * @param obj
>      *            The object to "toString".
>      * @param excludeFieldName
>      *            The field name to exclude
>      * @return The toString String.
>      */
>     public static String toStringExcluding(Object obj, final String
> excludeFieldName) {
>         return (new ReflectionToStringBuilder(obj) {
>             protected boolean accept(Field f) {
>                 return super.accept(f) &&
> !f.getName().equals(excludeFieldName);
>             }
>         }).toString();
>     }
> 
> I could imagine writing my call sites like this instead:
> 
> new ReflectionToStringBuilder(obj).setExcludeFields(new
> String[]{"password"}).toString();
> 
> Which means adding the set/getExcludeFields() feature.
> 
> Any thoughts?
> 
> Gary
> 
> 


-- 
Steven Caswell
steven.caswell@gmail.com

(c) 404-693-4148
(o) 404-260-2382

Take back the web - http://www.mozilla.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message