Module org.jooq
Package org.jooq

Class JSONFormat

java.lang.Object
org.jooq.JSONFormat

public final class JSONFormat extends Object
A JSON formatting type, which can be used to configure JSON imports / exports.

The default format is the following, using header() equal to true and applying JSONFormat.RecordFormat.ARRAY:


 {"fields":[{"name":"field-1","type":"type-1"},
            {"name":"field-2","type":"type-2"},
             ...,
            {"name":"field-n","type":"type-n"}],
 "records":[[value-1-1,value-1-2,...,value-1-n],
            [value-2-1,value-2-2,...,value-2-n]]}

If header() is set to false, then the result is simply the records array, either using JSONFormat.RecordFormat.ARRAY:


 [[value-1-1,value-1-2,...,value-1-n],
  [value-2-1,value-2-2,...,value-2-n]]

or, using JSONFormat.RecordFormat.OBJECT:


 [{"field-1": value-1-1, "field-2": value-1-2,..., "field-n": value-1-n},
  {"field-1": value-2-1, "field-2": value-2-2,..., "field-n": value-2-n}]

The type is immutable, meaning calls to setters like header(boolean) do not modify the original reference, but return a new one instead.

Author:
Lukas Eder
  • Field Details

    • DEFAULT_FOR_RESULTS

      public static final JSONFormat DEFAULT_FOR_RESULTS
    • DEFAULT_FOR_RECORDS

      public static final JSONFormat DEFAULT_FOR_RECORDS
  • Constructor Details

    • JSONFormat

      public JSONFormat()
  • Method Details

    • format

      @NotNull public final @NotNull JSONFormat format(boolean newFormat)
      The new value for the formatting flag, defaulting to false.
    • format

      public final boolean format()
      The formatting flag.
    • newline

      @NotNull public final @NotNull JSONFormat newline(String newNewline)
      The new newline character, defaulting to \n.
    • newline

      @NotNull public final @NotNull String newline()
      The formatting flag.
    • globalIndent

      @NotNull public final @NotNull JSONFormat globalIndent(int newGlobalIndent)
      The new global indentation size applied on all levels, defaulting to 0.
    • globalIndent

      public final int globalIndent()
      The global indentation applied on all levels.
    • indent

      @NotNull public final @NotNull JSONFormat indent(int newIndent)
      The new indentation size per level value, defaulting to 2.
    • indent

      public final int indent()
      The indentation size per level.
    • indentString

      @NotNull public final @NotNull String indentString(int level)
      Convenience method to get an indentation string at a given level.
    • header

      @NotNull public final @NotNull JSONFormat header(boolean newHeader)
      Whether to emit a header row with column names, defaulting to true.
    • header

      public final boolean header()
      Whether to emit a header row with column names, defaulting to true.
    • recordFormat

      @NotNull public final @NotNull JSONFormat recordFormat(JSONFormat.RecordFormat newRecordFormat)
      The record format to be applied, defaulting to JSONFormat.RecordFormat.ARRAY.
    • recordFormat

      @NotNull public final @NotNull JSONFormat.RecordFormat recordFormat()
      The record format to be applied, defaulting to JSONFormat.RecordFormat.ARRAY.
    • wrapSingleColumnRecords

      @NotNull public final @NotNull JSONFormat wrapSingleColumnRecords(boolean newWrapSingleColumnRecords)
      Whether to wrap single column records in the recordFormat().
    • wrapSingleColumnRecords

      public final boolean wrapSingleColumnRecords()
      Whether to wrap single column records in the recordFormat().
    • quoteNested

      @NotNull public final @NotNull JSONFormat quoteNested(boolean newQuoteNested)
      Whether nested JSON or JSONB content should be quoted like a string, or nested into JSON formatted output.
    • quoteNested

      public final boolean quoteNested()
      Whether nested JSON or JSONB content should be quoted like a string, or nested into JSON formatted output.