parispurchase / json-io

Automatically exported from code.google.com/p/json-io
0 stars 0 forks source link

serializing an empty ArrayList produces {} instead of [] #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. class X {ArrayList<String> list = new ArrayList<String>();}
2. X x = new X();
3. System.out.println(JsonWriter.toJson(x));

What is the expected output? What do you see instead?
Should produce: {"@type":"X","list":[],"this$0":{}}
But instead, it produces
{"@type":"X","list":{},"this$0":{}}

Note the curly braces for "list".  That signifies an empty object rather than 
an empty array.

Note also that if we do add an element to list:
    x.list.add("test");

We get:
{"@type":"vericle.server.ticket.FetchTicketsActionHandlerTest$X","list":["test"]
,"this$0":{}}

which signifies that list is really an array, not a regular object.

What version of the product are you using? On what operating system?
2.0.1 on linux

Original issue reported on code.google.com by eli...@espoc.com on 5 Apr 2013 at 9:55

GoogleCodeExporter commented 9 years ago
In JsonWriter.java, perhaps the method writeArray should be used on collections 
that are Lists or Sets?

Original comment by eli...@espoc.com on 5 Apr 2013 at 10:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This has been fixed.  Empty ArrayList (when the field type is ArrayList or 
there is an ArrayList[] of ArrayLists, json-io will correctly emit an empty [] 
for an empty ArrayList, just as it would use [ ] when the array contains more 
than one item.  It can do this because it picks up the ArrayList type from the 
field (or type of array).

The code is already checked into GitHub.  When the next major issue comes 
along, this will be released.  

Original comment by jdereg@gmail.com on 29 Sep 2013 at 2:58

GoogleCodeExporter commented 9 years ago
This issue has been corrected and is available in the json-io 2.2.32 release.

Original comment by jdereg@gmail.com on 13 Nov 2013 at 1:21