Class JsonSerializer.Builder<SELF extends JsonSerializer.Builder<SELF>>

Direct Known Subclasses:
JcsSerializer.Builder, Json5lSerializer.Builder, Json5Serializer.Builder, JsonSchemaSerializer.Builder, JsonSerializer.DefaultBuilder
Enclosing class:
JsonSerializer

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

    • Builder

      protected Builder()
      Constructor, default settings.
    • Builder

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

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

    • addBeanTypesJson

      Add "_type" properties when needed.

      If true, then "_type" properties will be added to beans if their type cannot be inferred through reflection.

      When present, this value overrides the Serializer.Builder#addBeanTypes() setting and is provided to customize the behavior of specific serializers in a SerializerSet.

      Token streams: the cursor's raw structural methods do not emit "_type"; however this setting IS honored by TokenWriter.object(Object) when walking a bean.

      Returns:
      This object.
    • addBeanTypesJson

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

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

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

      public SELF escapeSolidus()
      Prefix solidus '/' characters with escapes.

      If enabled, solidus (e.g. slash) characters should be escaped.

      The JSON specification allows for either format.
      However, if you're embedding JSON in an HTML script tag, this setting prevents confusion when trying to serialize <\/script>.

      Example:

      // Create a JSON serializer that escapes solidus characters. WriterSerializer serializer = Json5Serializer .create() .escapeSolidus() .build(); // Produces: "{foo:'<\/bar>'" String json = serializer.write(JsonMap.of("foo", "</bar>");

      Returns:
      This object.
    • escapeSolidus

      public SELF escapeSolidus(boolean value)
      Same as escapeSolidus() but allows you to explicitly specify the value.
      Parameters:
      value - The value for this setting.
      Returns:
      This object.
    • 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 WriterSerializer.Builder<SELF extends JsonSerializer.Builder<SELF>>
      Returns:
      The hashkey of this builder.