Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

bug when format Object[] #2132

Closed
libinglong opened this issue Nov 11, 2018 · 5 comments
Closed

bug when format Object[] #2132

libinglong opened this issue Nov 11, 2018 · 5 comments

Comments

@libinglong
Copy link

libinglong commented Nov 11, 2018

        Cpu cpu = new Cpu("intel", 3.3);
        Screen screen = new Screen(16, 9, "samsung");
        Student student = new Student();
        Computer computer = student.assembling(cpu,screen);
        cpu.setName("intell");
        
        Object[] objectArray = new Object[4];
        objectArray[0] = cpu;
        objectArray[1] = screen;
        objectArray[2] = "2";
        objectArray[3] = "3";
        List<Object> list1 = new ArrayList<>();
        list1.add(objectArray);
        list1.add(computer);
        String s = JSON.toJSONString(list1);
        System.out.println(s);

the output is [[{"name":"intell","speed":3.3},{"length":16,"name":"samsung","width":9},"2","3"],{"cpu":{"$ref":"$[0].null"},"screen":{"$ref":"$[0].null"}}]
I don't think the ".null" is the expected output,especially when i use alibaba/arthas debugging.it makes me uncomfortable.
you can find the logic in ObjectArrayCodec.write which result in the issue
@wenshao

@wenshao
Copy link
Member

wenshao commented Nov 18, 2018

please tell me which version

@libinglong
Copy link
Author

please tell me which version

the version is
1.2.53
by the way,the assertEquals of Issue2132 may be like "cpu":{"$ref":"$[0].[0]"}(now the output is "cpu":{"$ref":"$[0].null")

@libinglong
Copy link
Author

the class Computer in your Issue2132 test case don't have getters and setters @wenshao
with getters and setters,the test failed.the result is:
junit.framework.ComparisonFailure:
Expected :[[{"name":"intell","speed":3.3},{"height":9,"name":"samsung","width":16},"2","3"],{}]
Actual :[[{"name":"intell","speed":3.3},{"height":9,"name":"samsung","width":16},"2","3"],{"cpu":{"$ref":"$[0].null"},"screen":{"$ref":"$[0].null"}}]

@wucaiqiang
Copy link

when i use
String s = JSON.toJSONString(arr, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat);
There is still the problem

@wucaiqiang
Copy link

i use the newest version :1.2.60

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants