You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dongjoon Hyun (Jira)" <ji...@apache.org> on 2020/09/04 18:45:00 UTC
[jira] [Commented] (LANG-1542) ToStringBuilder.reflectionToString -
Wrong JSON format when object has a List/Array of Enum
[ https://issues.apache.org/jira/browse/LANG-1542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17190884#comment-17190884 ]
Dongjoon Hyun commented on LANG-1542:
-------------------------------------
Could you add `3.9` to the Affected version, please?
{code}
$ jshell -c commons-lang3-3.9.jar
| Welcome to JShell -- Version 11.0.8
| For an introduction type: /help intro
jshell> public enum MyEnum { FOOD };
| created enum MyEnum
jshell> public class Person { List<MyEnum> list = Arrays.asList(MyEnum.FOOD); }
| created class Person
jshell> org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString(new Person(), org.apache.commons.lang3.builder.ToStringStyle.JSON_STYLE)
$4 ==> "{\"list\":[FOOD]}"
{code}
> ToStringBuilder.reflectionToString - Wrong JSON format when object has a List/Array of Enum
> -------------------------------------------------------------------------------------------
>
> Key: LANG-1542
> URL: https://issues.apache.org/jira/browse/LANG-1542
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.10
> Environment: Open JDK 1.8
> Reporter: Trần Ngọc Khoa
> Priority: Major
> Fix For: 3.11
>
> Time Spent: 3.5h
> Remaining Estimate: 0h
>
> I'm trying to log an object to console with JSON style using {{ToStringBuilder.reflectionToString}} from {{commons-lang3:3.10}} but it seems generated a wrong JSON format.
> Problem happening when I have a list of enums in my field list.
>
> {code:java}
> This is the class:
> public class Person {
> private long id;
> private String name;
> private List<MyEnum> listEnums;
> //getter and setter
> public String toString(){
> return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
> }
> }
> {code}
>
> And {{MyEnum}}:
> {code:java}
> public enum MyEnum {
> FOOD,
> SPORT,
> BOOK,
> MUSIC
> }{code}
> When I call {{toString()}} of Person object. It shows like this
> {code:java}
> {
> "id": 1,
> "name": "Karl",
> "listEnums": [FRIDAY, MONDAY, TUESDAY]
> }{code}
>
> What I expected is:
> {code:java}
> {
> "id": 1,
> "name": "Karl",
> "listEnums": ["FRIDAY", "MONDAY", "TUESDAY"]
> }{code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)