From bf7ef5aee59981150e765195692dd3260795663c Mon Sep 17 00:00:00 2001 From: Harsh Date: Mon, 19 Oct 2026 23:13:05 +0530 Subject: [PATCH 1/2] docs: correct pretty printing guide --- UserGuide.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UserGuide.md b/UserGuide.md index d998d54f00..06afa09482 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -517,9 +517,7 @@ In the above example, an instance of the Id class can not be created without act The default JSON output that is provided by Gson is a compact JSON format. This means that there will not be any whitespace in the output JSON structure. Therefore, there will be no whitespace between field names and its value, object fields, and objects within arrays in the JSON output. As well, "null" fields will be ignored in the output (NOTE: null values will still be included in collections/arrays of objects). See the [Null Object Support](#null-object-support) section for information on configure Gson to output all null values. -If you would like to use the Pretty Print feature, you must configure your `Gson` instance using the `GsonBuilder`. The `JsonFormatter` is not exposed through our public API, so the client is unable to configure the default print settings/margins for the JSON output. For now, we only provide a default `JsonPrintFormatter` that has default line length of 80 character, 2 character indentation, and 4 character right margin. - -The following is an example shows how to configure a `Gson` instance to use the default `JsonPrintFormatter` instead of the `JsonCompactFormatter`: +To use pretty printing, configure your `Gson` instance with `GsonBuilder.setPrettyPrinting()`. This uses Gson's standard pretty formatting style, with a newline between lines, two spaces for indentation, and a space after JSON separators. For a custom style, use `GsonBuilder.setFormattingStyle(FormattingStyle)`; see the [`FormattingStyle` API](gson/src/main/java/com/google/gson/FormattingStyle.java) for the available options. ```java Gson gson = new GsonBuilder().setPrettyPrinting().create(); From 0106d400aae070d8f57bc4a0ecdb5f972b2dfc6e Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 20 Oct 2026 02:15:22 +0530 Subject: [PATCH 2/2] Update UserGuide.md Co-authored-by: Marcono1234 --- UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UserGuide.md b/UserGuide.md index 06afa09482..47eb0e871a 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -517,7 +517,7 @@ In the above example, an instance of the Id class can not be created without act The default JSON output that is provided by Gson is a compact JSON format. This means that there will not be any whitespace in the output JSON structure. Therefore, there will be no whitespace between field names and its value, object fields, and objects within arrays in the JSON output. As well, "null" fields will be ignored in the output (NOTE: null values will still be included in collections/arrays of objects). See the [Null Object Support](#null-object-support) section for information on configure Gson to output all null values. -To use pretty printing, configure your `Gson` instance with `GsonBuilder.setPrettyPrinting()`. This uses Gson's standard pretty formatting style, with a newline between lines, two spaces for indentation, and a space after JSON separators. For a custom style, use `GsonBuilder.setFormattingStyle(FormattingStyle)`; see the [`FormattingStyle` API](gson/src/main/java/com/google/gson/FormattingStyle.java) for the available options. +To use pretty printing, configure your `Gson` instance with `GsonBuilder.setPrettyPrinting()`. This uses Gson's standard pretty formatting style, with a newline between lines, two spaces for indentation, and a space after JSON separators. For a custom style, use `GsonBuilder.setFormattingStyle(FormattingStyle)`; see the [`FormattingStyle` API](https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/FormattingStyle.html) for the available options. ```java Gson gson = new GsonBuilder().setPrettyPrinting().create();