fyhack / google-gson

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

Pretty Printing Results in Omission of Comma following a Serialized Map #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Gson object with pretty printing: new 
GsonBuilder().setPrettyPrinting().create();
2. Serialize an object containing a map.

What is the expected output? What do you see instead?
As pretty JSON: {"baz":{}"fizzle":"bar"}

As compact JSON: {"baz":{},"fizzle":"bar"}

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

Please provide any additional information below.
Here's a simple example that produces the output above and demonstrates the 
problem:

package com.joelpm;

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class App {
  public static class Foo {
    private Map<String,String> baz;
    private String fizzle;

    public Foo(String fizzle) {
      this.baz = new HashMap<String,String>();
      this.fizzle = fizzle;
    }
  }

  public static void main(String[] args) {
    Foo quux = new Foo("bar");
    Gson gsonPretty = new GsonBuilder().setPrettyPrinting().create();
    Gson gsonRegular = new GsonBuilder().create();
    System.out.println("As pretty JSON: " + gsonPretty.toJson(quux));
    System.out.println("As compact JSON: " + gsonRegular.toJson(quux));
  }
}

Original issue reported on code.google.com by joel.me...@gmail.com on 12 Jan 2009 at 10:52

GoogleCodeExporter commented 9 years ago
This is fixed in the 1.3 beta release.  Added a test in r372 to ensure there is 
no
regression in latter releases.

Original comment by joel.leitch@gmail.com on 17 Jan 2009 at 10:36

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 1 Oct 2009 at 5:09