Gary, Thank you, your solution appears to do exactly what I need.
However my commons-lang-1.0.1.jar doesn't have the class
ReflectionToStringBuilder. Is that class new and not yet released?
Also your example requires one to know the field name ["myDate"]. To avoid
that I'm thinking I'll do something like
if (java.util.Date.class.equals(field.getType())) {...}
instead of
if ("myDate".equals(field.getName())) {...}
-Brian
> Here is one option below. Supporting formatting in ToStringStyle would be
> better of course. We can think about it for post 2.0 (or now).
>
> import java.lang.reflect.Field;
> import java.text.SimpleDateFormat;
> import java.util.Date;
>
> import org.apache.commons.lang.builder.ReflectionToStringBuilder;
>
> /**
> * @author <a href="mailto:[EMAIL PROTECTED]">Gary Gregory</a>
> * @version $Id: $
> */
> public class TestRTSB {
>
> private Date myDate = new Date();
> private int foo= 22;
>
> public static void main(String[] arguments) {
> System.out.println(new TestRTSB());
> }
>
> public String toString() {
> return (new ReflectionToStringBuilder(this) {
> protected Object getValue(Field field) throws
> IllegalArgumentException, IllegalAccessException {
> Object value = super.getValue(field);
> if ("myDate".equals(field.getName())) {
> return new
SimpleDateFormat("yyyy-MM-dd").format(value);
> } else {
> return value;
> }
> }
> }).toString();
> }
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]