You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2026/01/25 12:42:00 UTC

[jira] [Updated] (LANG-1452) MultilineRecursiveToStringStyle shouldn't recurse into a BigDecimal

     [ https://issues.apache.org/jira/browse/LANG-1452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-1452:
----------------------------------
    Summary: MultilineRecursiveToStringStyle shouldn't recurse into a BigDecimal  (was: MultilineRecursiveToStringStyle produces wrong output for BigDecimal)

> MultilineRecursiveToStringStyle shouldn't recurse into a BigDecimal
> -------------------------------------------------------------------
>
>                 Key: LANG-1452
>                 URL: https://issues.apache.org/jira/browse/LANG-1452
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 3.7
>            Reporter: Aleksey Novozhilov
>            Priority: Major
>              Labels: MultilineRecursiveToStringStyle
>
> Class has 2 BigDecimal fields:
> {code:java}
> BigDecimal biddecimal123 = new BigDecimal("123");
> BigDecimal biddecimal456 = new BigDecimal("456");
> {code}
> MultilineRecursiveToStringStyle produces this output:
> {quote}BDToString@36baf30c[
>  biddecimal123=java.math.BigDecimal@7adf9f5f[
>  intVal=<null>,
>  scale=0
>  ],
>  biddecimal456=java.math.BigDecimal@63961c42[
>  intVal=<null>,
>  scale=0
>  ]
>  ]
> {quote}
>  
> ToStringStyle.MULTI_LINE_STYLE doesn't have this problem. It was introduced with method
> {code:java}
> @Override
> public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value){code}
> of MultilineRecursiveToStringStyle. It doesnt'n treat BigDecimal as a primitive type. So I had to do the following to solve my issue:
>  
> {code:java}
> class FixedMultilineRecursiveToStringStyle extends MultilineRecursiveToStringStyle{
>     @Override
>     public void appendDetail(StringBuffer buffer, String fieldName, Object value) {
>         if (!BigDecimal.class.equals(value.getClass())){
>             super.appendDetail(buffer, fieldName, value);
>         } else {
>             buffer.append(value);
>         }
>     }
> }
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)