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

Michael F commented on LANG-1600:
---------------------------------

[~ggregory]

I propose to restore the handling of collections to its pre-3.11 state.
I created [pr#610|https://github.com/apache/commons-lang/pull/610] which pushes 
the recently-introduced changes for JSON-style down to {{JsonToStringStyle}}.

I added a bunch of test cases to cover non-empty collections, maps, and arrays 
in various styles.

> ToStringBuilder behavior for collections changed with 3.11
> ----------------------------------------------------------
>
>                 Key: LANG-1600
>                 URL: https://issues.apache.org/jira/browse/LANG-1600
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 3.11
>         Environment: {code:none}
> java -version
> openjdk version "1.8.0_242"
> OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
> OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)
> {code}
> commons-lang3-3.10.jar via maven central
> commons-lang3-3.11.jar via maven central
>            Reporter: Michael F
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The fix in LANG-1542 (git commit 
> [1dddec8|https://github.com/apache/commons-lang/commit/1dddec8ba867bc31233ba194f0753ea35818cbfd])
>  had side effects and did not just affect json styles, but {{DEFAULT_STYLE}}, 
> {{SHORT_PREFIX_STYLE}}, and possibly others as well.
> Also, collections are now treated differently when empty:
> Square brackets for empty list vs. curly brackets for non-empty lists.
> h3. Test case
> {code:java}
> new ToStringBuilder(new Object(), ToStringStyle.SHORT_PREFIX_STYLE)
>         .append("foo0", Collections.emptyList())
>         .append("foo1", Collections.singleton("1"))
>         .append("foo2", Arrays.asList("1", "2"))
>         .build();
> {code}
> h3. {{SHORT_PREFIX_STYLE}}
> Result for version 3.11:
> {code:none}
> Object[foo0=[],foo1={1},foo2={1,2}]
> {code}
> Expected (also as-is for 3.10)
> {code:none}
> Object[foo0=[],foo1=[1],foo2=[1, 2]]
> {code}
> h3. {{DEFAULT_STYLE}}
> Result for version 3.11
> {code:none}
> java.lang.Object@7960847b[foo0=[],foo1={1},foo2={1,2}]
> {code}
> Expected (also as-is for 3.10)
> {code:none}
> java.lang.Object@7960847b[foo0=[],foo1=[1],foo2=[1, 2]]
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to