discomarathon / google-gson

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

toJson inserts extraneous comma in Collection elements with pretty-printing turned on #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile and run the attached test case

What is the expected output? What do you see instead?

Expected:

xxx{"x":"hello","y":"world"}xxx
xxx[{"x":"hello","y":"world"}]xxx
xxx{"x":"hello","y":"world"}
xxx
xxx[{"x":"hello","y":"world"}]
xxx

Actual:

xxx{"x":"hello","y":"world"}xxx
xxx[{"x":"hello","y":"world"}]xxx
xxx{"x":"hello","y":"world"}
xxx
xxx[{,"x":"hello","y":"world"}]
xxx
Exception in thread "main" com.google.gson.JsonParseException: Failed
parsing JSON source: java.io.StringReader@860d49 to Json
    at com.google.gson.Gson.fromJson(Gson.java:383)
    at com.google.gson.Gson.fromJson(Gson.java:326)
    at PPTest.main(PPTest.java:39)
Caused by: com.google.gson.ParseException: Encountered "," at line 1, column 3.
Was expecting one of:
    "\"" ...
    "}" ...

    at com.google.gson.JsonParser.generateParseException(JsonParser.java:497)
    at com.google.gson.JsonParser.jj_consume_token(JsonParser.java:436)
    at com.google.gson.JsonParser.JsonObject(JsonParser.java:57)
    at com.google.gson.JsonParser.JsonValue(JsonParser.java:141)
    at com.google.gson.JsonParser.Elements(JsonParser.java:117)
    at com.google.gson.JsonParser.JsonArray(JsonParser.java:103)
    at com.google.gson.JsonParser.parse(JsonParser.java:25)
    at com.google.gson.Gson.fromJson(Gson.java:375)
    ... 2 more

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

Gson 1.2 with Sun Java 1.6.0_07 (Ubuntu package sun-java6-jdk=6-07-3ubuntu2

Please provide any additional information below.

Original issue reported on code.google.com by christop...@gmail.com on 28 Sep 2008 at 9:00

Attachments:

GoogleCodeExporter commented 9 years ago
This is a duplicate of issue #49

Original comment by joel.leitch@gmail.com on 29 Sep 2008 at 10:01