You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <gg...@seagullsoftware.com> on 2005/10/05 02:13:44 UTC
RE: [lang] Using ReflectionToStringBuilder and excluding secure fields
Hello:
I've checked into SVN an experimental version with unit tests.
Please let me know if that would suit you needs as it does mine ;-)
Gary
> -----Original Message-----
> From: Steven Caswell [mailto:steven.caswell@gmail.com]
> Sent: Saturday, August 06, 2005 3:28 PM
> To: Jakarta Commons Developers List
> Subject: Re: [lang] Using ReflectionToStringBuilder and excluding
secure
> fields
>
> +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 <gg...@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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org