Class FormattingStyle

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static FormattingStyle COMPACT
      The default compact formatting style: no newline no indent no space after ',' and ':'
      private java.lang.String indent  
      private java.lang.String newline  
      static FormattingStyle PRETTY
      The default pretty printing formatting style: "\n" as newline two spaces as indent a space between ':' and the subsequent value
      private boolean spaceAfterSeparators  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FormattingStyle​(java.lang.String newline, java.lang.String indent, boolean spaceAfterSeparators)  
    • Field Detail

      • newline

        private final java.lang.String newline
      • indent

        private final java.lang.String indent
      • spaceAfterSeparators

        private final boolean spaceAfterSeparators
      • COMPACT

        public static final FormattingStyle COMPACT
        The default compact formatting style:
        • no newline
        • no indent
        • no space after ',' and ':'
      • PRETTY

        public static final FormattingStyle PRETTY
        The default pretty printing formatting style:
        • "\n" as newline
        • two spaces as indent
        • a space between ':' and the subsequent value
    • Constructor Detail

      • FormattingStyle

        private FormattingStyle​(java.lang.String newline,
                                java.lang.String indent,
                                boolean spaceAfterSeparators)
    • Method Detail

      • withNewline

        public FormattingStyle withNewline​(java.lang.String newline)
        Creates a FormattingStyle with the specified newline setting.

        It can be used to accommodate certain OS convention, for example hardcode "\n" for Linux and macOS, "\r\n" for Windows, or call System.lineSeparator() to match the current OS.

        Only combinations of \n and \r are allowed.

        Parameters:
        newline - the string value that will be used as newline.
        Returns:
        a newly created FormattingStyle
        See Also:
        getNewline()
      • withIndent

        public FormattingStyle withIndent​(java.lang.String indent)
        Creates a FormattingStyle with the specified indent string.

        Only combinations of spaces and tabs are allowed in indent.

        Parameters:
        indent - the string value that will be used as indent.
        Returns:
        a newly created FormattingStyle
        See Also:
        getIndent()
      • withSpaceAfterSeparators

        public FormattingStyle withSpaceAfterSeparators​(boolean spaceAfterSeparators)
        Creates a FormattingStyle which either uses a space after the separators ',' and ':' in the JSON output, or not.

        This setting has no effect on the configured newline. If a non-empty newline is configured, it will always be added after ',' and no space is added after the ',' in that case.

        Parameters:
        spaceAfterSeparators - whether to output a space after ',' and ':'.
        Returns:
        a newly created FormattingStyle
        See Also:
        usesSpaceAfterSeparators()
      • getNewline

        public java.lang.String getNewline()
        Returns the string value that will be used as a newline.
        Returns:
        the newline value.
        See Also:
        withNewline(String)
      • getIndent

        public java.lang.String getIndent()
        Returns the string value that will be used as indent.
        Returns:
        the indent value.
        See Also:
        withIndent(String)
      • usesSpaceAfterSeparators

        public boolean usesSpaceAfterSeparators()
        Returns whether a space will be used after ',' and ':'.
        See Also:
        withSpaceAfterSeparators(boolean)