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 Print generates invalid JSON #49

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

Pretty Print generates invalid JSON #49

GoogleCodeExporter opened this issue Mar 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Version: 1.2

The following code returns an invalid JSON string:

-----

import java.util.ArrayList;
import java.util.List;

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

public class App {
    public static void main(String[] args) {
        Node root = new Node("root");
        root.createChild("Pete");

        Gson gson = new GsonBuilder()
                .setPrettyPrinting()
                .create();

        System.out.println(gson.toJson(root));
    }
}

class Node {
    private final String name;
    private final List<Node> children = new ArrayList<Node>();

    public Node(String name) {
        this.name = name;
    }

    public Node createChild(String childName) {
        Node child = new Node(childName);
        children.add(child);
        return child;
    }
}

Original issue reported on code.google.com by b.richt...@gmail.com on 27 Sep 2008 at 5:54

@GoogleCodeExporter
Copy link
Author

Below is the output from the above program:
{"name":"root","children":[{,"name":"Pete","children":[]}]}

Notice the extra "," instead the "children" array.

Original comment by joel.leitch@gmail.com on 27 Sep 2008 at 6:42

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Fix submitted in r251.

Original comment by joel.leitch@gmail.com on 27 Sep 2008 at 7:10

  • Changed state: Fixed

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