You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Matias Busso (JIRA)" <ji...@apache.org> on 2019/04/22 19:27:00 UTC

[jira] [Commented] (LANG-1249) Exclude Fields on ReflectionToStringBuilder doesn't work for inner objects

    [ https://issues.apache.org/jira/browse/LANG-1249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16823366#comment-16823366 ] 

Matias Busso commented on LANG-1249:
------------------------------------

The issue starts at this point (RecursiveToStringStyle.java) :
{code:java}
  @Override
    public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) {
        if (!ClassUtils.isPrimitiveWrapper(value.getClass()) &&
            !String.class.equals(value.getClass()) &&
            accept(value.getClass())) {
            buffer.append(ReflectionToStringBuilder.toString(value, this));
        } else {
            super.appendDetail(buffer, fieldName, value);
        }
    }{code}
When you try to exclude a field of an inner object a ReflectionToStringBuilder new instance is created. Therefore the exclude field names for the previous instance si not passed through the new one. I tried to fix it but it breaks the contract between ReflectionToStringBuilder and RecursiveToStringStyle. It seems that either a refactor is necessary in order to support inner exclusion or update the documentation to clarify the use case.

 

> Exclude Fields on ReflectionToStringBuilder doesn't work for inner objects
> --------------------------------------------------------------------------
>
>                 Key: LANG-1249
>                 URL: https://issues.apache.org/jira/browse/LANG-1249
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: bharat
>            Priority: Major
>
> Class Foo {
> String a;
> Bar bar;
> }
> Class Bar {
> String b;
> }
> Foo f = new Foo();
>  ReflectionToStringBuilder builder = new ReflectionToStringBuilder(f, new RecursiveToStringStyle());
>  builder.setExcludeFieldNames("bar"); // this works
>  builder.setExcludeFieldNames("b"); // this doesn't work (It doesn't exclude this field. It only excludes top level fields of Class Foo (f in the example above)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)