GutoVeronezi opened a new pull request #849:
URL: https://github.com/apache/commons-lang/pull/849


   As commented in JIRA issue 
[LANG-1662](https://issues.apache.org/jira/browse/LANG-1662)  and the maillist 
([here](https://lists.apache.org/thread/348sxhc277r45hkwt39rpdwxmxt5lrrs) and 
[here](https://lists.apache.org/thread/4nxrlfrzssv5w09c2gs9sphn7rgoc613)), the 
class **ReflectionToStringBuilder** has methods to exclude fields from 
*toString*; If we have an object with several fields and want to reflect only 
some, we have to list all the fields that we don't want to reflect and pass to 
**excludeFieldNames**. 
   
   To examplify what I mean:
   
   - In a case which we need to print only the fields `a`,  `b` and `e` from 
the class `UseCase`, the current solution is:
   
   ```java
          Example example = new UseCase.Example();
          example.setA("test");
          example.setB(1);
          example.setC(1.1);
          example.setD(true);
          example.setE(false);
          example.setF(false);
          example.setG(true);
   
          ToStringBuilder toStringBuilder = new ToStringBuilder(example,
          ToStringStyle.JSON_STYLE);
          toStringBuilder.append("a", example.getA());
          toStringBuilder.append("b", example.getB());
          toStringBuilder.append("e", example.isE());
          System.out.println(toStringBuilder.build());
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to