Skip to content

docs: correct pretty printing guide - #3149

Open
Mr-KnightCLI wants to merge 2 commits into
google:mainfrom
Mr-KnightCLI:docs-correct-pretty-printing-guide
Open

Mr-KnightCLI wants to merge 2 commits into
google:mainfrom
Mr-KnightCLI:docs-correct-pretty-printing-guide

Conversation

@Mr-KnightCLI

Copy link
Copy Markdown

Purpose

Description

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

@Marcono1234 Marcono1234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this outdated documentation!

I have two small suggestions, hopefully they are useful.

Comment thread UserGuide.md Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a bit clearer if this said "line feed" instead of "newline"?

Suggested change
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 line feed (`\n`) 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.

Comment thread UserGuide.md Resolved
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants