Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants