commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jamie Bisotti" <jbiso...@gmail.com>
Subject Re: [Lang] ToStringBuilder Question
Date Thu, 19 Apr 2007 18:09:47 GMT
On 4/19/07, ben short <ben@benshort.co.uk> wrote:
>
> Hi Gary,
>
> I was using version 2.2 but have tried it again with version 2.3. Same
> result.
> I also tried the following code.
>
> ToStringBuilder.reflectionToString(request)
>
> But that produces the same output.
>
> Interestingly if i do the same but with one of my domain object,
> instead of the HttpServletRequest I see an expected result.
>
> Looking at the javadoc it states..
>
> [SNIP]
> Alternatively, there is a method that uses reflection to determine the
> fields to test. Because these fields are usually private, the method,
> reflectionToString, uses AccessibleObject.setAccessible to change the
> visibility of the fields. This will fail under a security manager,
> unless the appropriate permissions are set up correctly. It is also
> slower than testing explicitly.
> [SNIP]
>
> I wonder if this has anything todo with it?
>
> Regards
>
> Ben
>
> On 4/19/07, Gary Gregory <ggregory@seagullsoftware.com> wrote:
> > Hello Ben:
> >
> > It should be possible indeed. This is the kind of thing with which this
> builder was designed and tested. Make sure you are using the current version
> of lang (2.3). Does it happen if you use the single arg method?
> >
> > If you take a peek at the unit tests you'll see that the class is tested
> to output fields from nested objects to any depth. So I really wonder what
> is going on.
> >
> > You could also write a test case with no external dependencies if you
> need to file a JIRA ticket.
> >
> > Thank you,
> > Gary
> >
> > > -----Original Message-----
> > > From: jamin.short@gmail.com [mailto:jamin.short@gmail.com] On Behalf
> Of ben
> > > short
> > > Sent: Wednesday, April 18, 2007 8:11 AM
> > > To: commons-user@jakarta.apache.org
> > > Subject: [Lang] ToStringBuilder Question
> > >
> > > Hi,
> > >
> > > Im trying to use the ToStringBuilder as follows,
> > >
> > > ToStringBuilder.reflectionToString(request,
> ToStringStyle.MULTI_LINE_STYLE)
> > >
> > > the output I get is....
> > >
> > > org.apache.catalina.connector.RequestFacade@19bd8b4[
> > >   request=org.apache.catalina.connector.Request@1acf711
> > > ]
> > >
> > >
> > > I was hoping that the output would be more verbose and output all of
> > > the request properties.
> > >
> > > Is this possible?
> > >
> > > Regards
> > >
> > > Ben
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
I *think* this is expected behavior.  ToStringBuilder.reflectionToString(
Object ) is not recursive; it uses reflection on the supplied Object only.
Primitives values are printed as-is, while Object values are determined by
calling Object.toString().

So, org.apache.catalina.connector.RequestFacade class does not implement
toString() so reflection is used to determine it has a single member
variable named "request" (which appears in your output).  That member
variable is an Object, so toString() is called to determine it's value;
unfortunately, org.apache.catalina.connector.Request does not implement
toString() either.  Meaning, I think the output you are seeing is correct.

-- 
Jamie Bisotti

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