You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Roberto Wander Bezerra da Costa (Jira)" <ji...@apache.org> on 2020/06/09 19:46:00 UTC

[jira] [Commented] (LANG-1543) [JSON string for maps] ToStringBuilder.reflectionToString doesnt render nested maps correctly.

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

Roberto Wander Bezerra da Costa commented on LANG-1543:
-------------------------------------------------------

It seems to me that since when *ToStringStyle.JSON_STYLE* was introduced (*3.4*) it never supported navigation through maps. Maybe this is a feature request, but I'm not sure where to look at.

> [JSON string for maps] ToStringBuilder.reflectionToString doesnt render nested maps correctly.
> ----------------------------------------------------------------------------------------------
>
>                 Key: LANG-1543
>                 URL: https://issues.apache.org/jira/browse/LANG-1543
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.10
>            Reporter: Swaraj Pal
>            Priority: Major
>
> Nested Maps are not converted correctly as JSON using ToStringBuilder.reflectToString commons-lang3:3.10 . Please find below the example to reproduce:-
> Class:
> {code:java}
> public class Student {    
>     private String name;
>     private Map<String, String> education;
>     //getters and setters...
>     public String toString() {
>         return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
>     }}
> {code}
>  
> Driver test:
> {code:java}
>         Student p = new Student();
>         p.setName("como");
>         
>         Map<String, String> educationMap = new HashMap<String, String>();
>         educationMap.put("primary", "school");
>         educationMap.put("graduation", "B.S.");
>         
>         p.setEducation(educationMap);
>         
>         System.out.println(p.toString());
> {code}
> The toString() prints
> {code:java}
> {"education":{graduation=B.S., primary=school},"name":"como"}
> {code}
> but I expect as JSON it should print as below (with proper key,value pairs as field names and values)
> {code:java}
> {"education":{"graduation": "B.S.", "primary":"school"},"name":"como"}
> {code}
> Suggested fix:
> I can create a Pull request for this issue handling Maps appending logic.



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