discomarathon / google-gson

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

Invalid serialization of a Map with null values #99

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

public class GsonTest {

    private static class TestType {
        Map<String, String> map = new TreeMap<String, String>();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        TestType t = new TestType();
        t.map.put("name1", null);
        t.map.put("name2", "value2");

        Gson gson = new Gson();
        System.out.println(gson.toJson(t));
    }

}

The output is:
{"map":{,"name2":"value2"}}

Note the extra comma at the beginning of the map.

The expected output is:
{"map":{"name2":"value2"}}

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

This is gson 1.2.3 on Ubuntu 8.10 64-bit.

Original issue reported on code.google.com by gary...@gmail.com on 8 Feb 2009 at 6:55

GoogleCodeExporter commented 9 years ago
Added tests in r387 but can not reproduce the bug

Original comment by inder123 on 3 Mar 2009 at 9:09