Class WriterSerializer.Builder<SELF extends WriterSerializer.Builder<SELF>>

Direct Known Subclasses:
CsvSerializer.Builder, HjsonSerializer.Builder, HoconSerializer.Builder, IniSerializer.Builder, JsonSerializer.Builder, MarkdownSerializer.Builder, PlainTextSerializer.Builder, RdfSerializer.Builder, SseSerializer.Builder, TomlSerializer.Builder, UonSerializer.Builder, WriterSerializer.DefaultBuilder, XmlSerializer.Builder, YamlSerializer.Builder
Enclosing class:
WriterSerializer

public abstract static class WriterSerializer.Builder<SELF extends WriterSerializer.Builder<SELF>> extends Serializer.Builder<SELF>
Builder class.
  • Constructor Details

    • Builder

      protected Builder()
      Constructor, default settings.
    • Builder

      protected Builder(WriterSerializer.Builder<?> copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The builder to copy from.
      Cannot be null.
    • Builder

      protected Builder(WriterSerializer copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The bean to copy from.
      Cannot be null.
  • Method Details

    • build

      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class Serializer.Builder<SELF extends WriterSerializer.Builder<SELF>>
      Returns:
      The built object.
    • copy

      public abstract SELF copy()
      Description copied from class: Context.Builder
      Copy creator.
      Specified by:
      copy in class Serializer.Builder<SELF extends WriterSerializer.Builder<SELF>>
      Returns:
      A new mutable copy of this builder.
    • hashKey

      public HashKey hashKey()
      Description copied from class: Context.Builder
      Returns the hashkey of this builder.

      Used to return previously instantiated context beans that have matching hashkeys. The HashKey object is suitable for use as a hashmap key of a map of context beans. A context bean is considered equivalent if the HashKey.equals(Object) method is the same.

      Overrides:
      hashKey in class Serializer.Builder<SELF extends WriterSerializer.Builder<SELF>>
      Returns:
      The hashkey of this builder.
    • maxIndent

      public SELF maxIndent(int value)
      Maximum indentation.

      Specifies the maximum indentation level in the serialized document.

      Notes:
      • This setting does not apply to the RDF serializers.
      Example:

      // Create a serializer that indents a maximum of 20 tabs. WriterSerializer serializer = JsonSerializer .create() .ws() // Enable whitespace .maxIndent(20) .build();

      Parameters:
      value - The new value for this property.
      The default is 100.
      Returns:
      This object.
    • quoteChar

      public SELF quoteChar(char value)
      Quote character.

      Specifies the character to use for quoting attributes and values.

      Notes:
      • This setting does not apply to the RDF serializers.
      Example:

      // Create a serializer that uses single quotes. WriterSerializer serializer = JsonSerializer .create() .quoteChar('\'') .build(); // A bean with a single property public class MyBean { public String foo = "bar"; } // Produces {'foo':'bar'} String json = serializer.toString(new MyBean());

      Parameters:
      value - The new value for this property.
      The default is '"'.
      Returns:
      This object.
    • quoteCharOverride

      public SELF quoteCharOverride(char value)
      Quote character override.

      Similar to quoteChar(char) but takes precedence over that setting.

      Allows you to override the quote character even if it's set by a subclass such as Json5Serializer.

      Parameters:
      value - The new value for this property.
      The default is null.
      Returns:
      This object.
    • sq

      public SELF sq()
      Quote character.

      Specifies to use single quotes for quoting attributes and values.

      Notes:
      • This setting does not apply to the RDF serializers.
      Example:

      // Create a serializer that uses single quotes. WriterSerializer serializer = JsonSerializer .create() .sq() .build(); // A bean with a single property public class MyBean { public String foo = "bar"; } // Produces {'foo':'bar'} String json = serializer.toString(new MyBean());

      Returns:
      This object.
    • streamCharset

      public SELF streamCharset(Charset value)
      Output stream charset.

      The character set to use when writing to OutputStreams.

      Used when passing in output streams and byte arrays to Serializer.write(Object, Object).

      Example:

      // Create a serializer that writes UTF-8 files. WriterSerializer serializer = JsonSerializer .create() .streamCharset(Charset.forName("UTF-8")) .build(); // Use it to write to a UTF-8 encoded output stream. serializer.serializer(new FileOutputStreamStream("MyBean.txt"), myBean);

      Parameters:
      value - The new value for this property.
      The default is the system JVM setting.
      Can be null (defaults to UTF-8).
      Returns:
      This object.
    • useWhitespace

      public SELF useWhitespace()
      Use whitespace.

      When enabled, whitespace is added to the output to improve readability.

      Example:

      // Create a serializer with whitespace enabled. WriterSerializer serializer = JsonSerializer .create() .useWhitespace() .build(); // A bean with a single property public class MyBean { public String foo = "bar"; } // Produces "\{\n\t"foo": "bar"\n\}\n" String json = serializer.write(new MyBean());

      Returns:
      This object.
    • useWhitespace

      public SELF useWhitespace(boolean value)
      Same as useWhitespace() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • ws

      public SELF ws()
      Use whitespace.

      When enabled, whitespace is added to the output to improve readability.

      Example:

      // Create a serializer with whitespace enabled. WriterSerializer serializer = JsonSerializer .create() .ws() .build(); // A bean with a single property public class MyBean { public String foo = "bar"; } // Produces "\{\n\t"foo": "bar"\n\}\n" String json = serializer.write(new MyBean());

      Returns:
      This object.