Navigation Menu

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

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

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Milestone-Release1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant