Class JsonWriter

java.lang.Object
com.azure.json.JsonWriter
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
DefaultJsonWriter, GsonJsonWriter

public abstract class JsonWriter extends Object implements Closeable
Writes a JSON encoded value to a stream.
  • Constructor Details

    • JsonWriter

      public JsonWriter()
  • Method Details

    • getWriteContext

      public abstract JsonWriteContext getWriteContext()
      Gets the current writing context for the JSON object.

      The writing context can help determine whether a write operation would be illegal.

      The initial write context is JsonWriteContext.ROOT.

      Returns:
      The current writing context.
    • close

      public abstract void close() throws IOException
      Closes the JSON stream.

      If the writing context isn't JsonWriteContext.COMPLETED when this is called an IllegalStateException will be thrown.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IllegalStateException - If the JsonWriter is closed before the writing context is JsonWriteContext.COMPLETED.
      IOException
    • flush

      public abstract JsonWriter flush()
      Flushes any un-flushed content written to this writer.

      It should be assumed that each write call won't flush any contents.

      Returns:
      The flushed JsonWriter object.
    • writeStartObject

      public abstract JsonWriter writeStartObject()
      Writes a JSON start object ({).
      Returns:
      The updated JsonWriter object.
    • writeStartObject

      public final JsonWriter writeStartObject(String fieldName)
      Writes a JSON start object ({) with a preceding field name.

      This API is the equivalent of calling writeFieldName(String) and writeStartObject(), in that order.

      Parameters:
      fieldName - The field name.
      Returns:
      The updated JsonWriter object.
    • writeEndObject

      public abstract JsonWriter writeEndObject()
      Writes a JSON end object (}).

      If the current writing context isn't an object an IllegalStateException will be thrown.

      Returns:
      The updated JsonWriter object.
    • writeStartArray

      public abstract JsonWriter writeStartArray()
      Writes a JSON start array ([).
      Returns:
      The updated JsonWriter object.
    • writeStartArray

      public final JsonWriter writeStartArray(String fieldName)
      Writes a JSON start array ([) with a preceding field name.

      This API is the equivalent of calling writeFieldName(String) and writeStartArray(), in that order.

      Parameters:
      fieldName - The field name.
      Returns:
      The updated JsonWriter object.
    • writeEndArray

      public abstract JsonWriter writeEndArray()
      Writes a JSON end array (]).
      Returns:
      The updated JsonWriter object.
    • writeFieldName

      public abstract JsonWriter writeFieldName(String fieldName)
      Writes a JSON field name ("fieldName":).
      Parameters:
      fieldName - The field name.
      Returns:
      The updated JsonWriter object.
    • writeJson

      public final JsonWriter writeJson(JsonSerializable<?> value)
      Writes a JsonSerializable object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeJson(JsonSerializable, boolean) to indicate whether null should be written.

      This API is used instead of writeJsonField(String, JsonSerializable) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - JsonSerializable object to write.
      Returns:
      The updated JsonWriter object.
    • writeArray

      public final <T> JsonWriter writeArray(T[] array, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array.

      This API will begin by writing the start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      If the passed array is null JSON null will be written. If null shouldn't be written use writeArray(Object[], boolean, BiConsumer) and pass false for writeNull.

      This API is used instead of writeArrayField(String, Object[], BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The array element type.
      Parameters:
      array - The array being written.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArray

      public final <T> JsonWriter writeArray(T[] array, boolean writeNull, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array.

      This API will begin by writing the start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      writeNull determines whether JSON null should be written if array is null.

      This API is used instead of writeArrayField(String, Object[], boolean, BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The array element type.
      Parameters:
      array - The array being written.
      writeNull - Whether JSON null should be written if array is null.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArray

      public final <T> JsonWriter writeArray(Iterable<T> array, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array.

      This API will begin by writing the start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      If the passed array is null JSON null will be written. If null shouldn't be written use writeArray(Iterable, boolean, BiConsumer) and pass false for writeNull.

      This API is used instead of writeArrayField(String, Iterable, BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The array element type.
      Parameters:
      array - The array being written.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArray

      public final <T> JsonWriter writeArray(Iterable<T> array, boolean writeNull, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array.

      This API will begin by writing the start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      writeNull determines whether JSON null should be written if map is null.

      This API is used instead of writeArrayField(String, Iterable, boolean, BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The array element type.
      Parameters:
      array - The array being written.
      writeNull - Whether JSON null should be written if array is null.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeMap

      public final <T> JsonWriter writeMap(Map<String,T> map, BiConsumer<JsonWriter,T> valueWriterFunc)
      Writes a JSON map.

      This API will begin by writing the start object (&#123;) followed by key-value fields in the map using the valueWriterFunc and finishing by writing the end object (&#125;).

      If the passed map is null JSON null will be written. If null shouldn't be written use writeMap(Map, boolean, BiConsumer) and pass false for writeNull.

      This API is used instead of writeMapField(String, Map, BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The value element type.
      Parameters:
      map - The map being written.
      valueWriterFunc - The function that writes value of each key-value pair in the map.
      Returns:
      The updated JsonWriter object.
    • writeMap

      public final <T> JsonWriter writeMap(Map<String,T> map, boolean writeNull, BiConsumer<JsonWriter,T> valueWriterFunc)
      Writes a JSON map.

      This API will begin by writing the start object (&#123;) followed by key-value fields in the map using the valueWriterFunc and finishing by writing the end object (&#125;).

      writeNull determines whether JSON null should be written if map is null.

      This API is used instead of writeMapField(String, Map, boolean, BiConsumer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Type Parameters:
      T - The value element type.
      Parameters:
      map - The map being written.
      writeNull - Whether JSON null should be written if map is null.
      valueWriterFunc - The function that writes value of each key-value pair in the map.
      Returns:
      The updated JsonWriter object.
    • writeJson

      public final JsonWriter writeJson(JsonSerializable<?> value, boolean writeNull)
      Writes a JsonSerializable object.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeJsonField(String, JsonSerializable, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - JsonSerializable object to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeBinary

      public abstract JsonWriter writeBinary(byte[] value)
      Writes a JSON binary value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeBinary(byte[], boolean) to indicate whether null should be written.

      This API is used instead of writeBinaryField(String, byte[]) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Binary value to write.
      Returns:
      The updated JsonWriter object.
    • writeBinary

      public final JsonWriter writeBinary(byte[] value, boolean writeNull)
      Writes a JSON binary value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeBinaryField(String, byte[], boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Binary value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeBoolean

      public abstract JsonWriter writeBoolean(boolean value)
      Writes a JSON boolean value (true or false).

      This API is used instead of writeBooleanField(String, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the nullable Boolean use writeBoolean(Boolean).

      Parameters:
      value - boolean value to write.
      Returns:
      The updated JsonWriter object.
    • writeBoolean

      public final JsonWriter writeBoolean(Boolean value)
      Writes a nullable JSON boolean value (true, false, or null).

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeBoolean(Boolean, boolean) to indicate whether null should be written.

      This API is used instead of writeBooleanField(String, Boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the primitive boolean use writeBoolean(boolean).

      Parameters:
      value - Boolean value to write.
      Returns:
      The updated JsonWriter object.
    • writeBoolean

      public final JsonWriter writeBoolean(Boolean value, boolean writeNull)
      Writes a nullable JSON boolean value (true, false, or null).

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeBooleanField(String, Boolean, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Boolean value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeDouble

      public abstract JsonWriter writeDouble(double value)
      Writes a JSON double value.

      This API is used instead of writeDoubleField(String, double) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the nullable Double use writeDouble(Double).

      Parameters:
      value - double value to write.
      Returns:
      The updated JsonWriter object.
    • writeDouble

      public final JsonWriter writeDouble(Double value)
      Writes a nullable JSON double value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeDouble(Double, boolean) to indicate whether null should be written.

      This API is used instead of writeDoubleField(String, Double) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the primitive double use writeDouble(double).

      Parameters:
      value - Double value to write.
      Returns:
      The updated JsonWriter object.
    • writeDouble

      public final JsonWriter writeDouble(Double value, boolean writeNull)
      Writes a nullable JSON double value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeDoubleField(String, Double, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Double value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeFloat

      public abstract JsonWriter writeFloat(float value)
      Writes a JSON float value.

      This API is used instead of writeFloatField(String, float) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the nullable Float use writeFloat(Float).

      Parameters:
      value - float value to write.
      Returns:
      The updated JsonWriter object.
    • writeFloat

      public final JsonWriter writeFloat(Float value)
      Writes a nullable JSON float value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeFloat(Float, boolean) to indicate whether null should be written.

      This API is used instead of writeFloatField(String, Float) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the primitive float use writeFloat(float).

      Parameters:
      value - Float value to write.
      Returns:
      The updated JsonWriter object.
    • writeFloat

      public final JsonWriter writeFloat(Float value, boolean writeNull)
      Writes a nullable JSON float value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeFloatField(String, Float, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Float value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeInt

      public abstract JsonWriter writeInt(int value)
      Writes a JSON int value.

      This API is used instead of writeIntField(String, int) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the nullable Integer use writeInteger(Integer).

      Parameters:
      value - int value to write.
      Returns:
      The updated JsonWriter object.
    • writeInteger

      public final JsonWriter writeInteger(Integer value)
      Writes a nullable JSON int value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeInteger(Integer, boolean) to indicate whether null should be written.

      This API is used instead of writeIntegerField(String, Integer) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the primitive int use writeInt(int).

      Parameters:
      value - Integer value to write.
      Returns:
      The updated JsonWriter object.
    • writeInteger

      public final JsonWriter writeInteger(Integer value, boolean writeNull)
      Writes a nullable JSON integer value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeIntegerField(String, Integer, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Integer value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeLong

      public abstract JsonWriter writeLong(long value)
      Writes a JSON long value.

      This API is used instead of writeLongField(String, long) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the nullable Long use writeLong(Long).

      Parameters:
      value - long value to write.
      Returns:
      The updated JsonWriter object.
    • writeLong

      public final JsonWriter writeLong(Long value)
      Writes a nullable JSON long value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeLong(Long, boolean) to indicate whether null should be written.

      This API is used instead of writeLongField(String, Long) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      For the primitive long use writeLong(long).

      Parameters:
      value - Long value to write.
      Returns:
      The updated JsonWriter object.
    • writeLong

      public final JsonWriter writeLong(Long value, boolean writeNull)
      Writes a nullable JSON long value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeLongField(String, Long, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - Long value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeNull

      public abstract JsonWriter writeNull()
      Writes a JSON null.

      This API is used instead of writeNullField(String) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Returns:
      The updated JsonWriter object.
    • writeString

      public abstract JsonWriter writeString(String value)
      Writes a JSON String value.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeString(String, boolean) to indicate whether null should be written.

      This API is used instead of writeStringField(String, String) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - String value to write.
      Returns:
      The updated JsonWriter object.
    • writeString

      public final JsonWriter writeString(String value, boolean writeNull)
      Writes a nullable JSON String value.

      If writeNull is false and value is null a value won't be written, effectively treating the call as a no-op.

      This API is used instead of writeStringField(String, String, boolean) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - String value to write.
      writeNull - Whether a null value should be written.
      Returns:
      The updated JsonWriter object.
    • writeRawValue

      public abstract JsonWriter writeRawValue(String value)
      Writes the passed value literally without any additional handling.

      Use this API when writing a String value that is already properly formatted JSON, such as a JSON string ("\"string\""), number ("42", "42.0"), boolean ("true", "false"), null ("null"), array ("[\"string\", \"array\"]"), or object ({"\"field\":\"value\""}).

      This API is used instead of writeRawField(String, String) when the value needs to be written to the root of the JSON value, as an element in an array, or after a call to writeFieldName(String).

      Parameters:
      value - The raw JSON value to write.
      Returns:
      The updated JsonWriter object.
    • writeJsonField

      public final JsonWriter writeJsonField(String fieldName, JsonSerializable<?> value)
      Writes a JsonSerializable field.

      Combines writeFieldName(String) and writeJson(JsonSerializable) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeJsonField(String, JsonSerializable, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - JsonSerializable object to write.
      Returns:
      The updated JsonWriter object.
    • writeArrayField

      public final <T> JsonWriter writeArrayField(String fieldName, T[] array, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array field.

      This API will begin by writing the field name and start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      If the passed array is null a JSON null field will be written. If a null field shouldn't be written use writeArrayField(String, Object[], boolean, BiConsumer) and pass false for writeNull.

      Combines writeFieldName(String) and writeArray(Object[], BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The array element type.
      Parameters:
      fieldName - The field name.
      array - The array being written.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArrayField

      public final <T> JsonWriter writeArrayField(String fieldName, T[] array, boolean writeNull, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array field.

      This API will begin by writing the field name and start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      writeNull determines whether a JSON null field should be written if array is null.

      Combines writeFieldName(String) and writeArray(Object[], boolean, BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The array element type.
      Parameters:
      fieldName - The field name.
      array - The array being written.
      writeNull - Whether JSON null should be written if array is null.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArrayField

      public final <T> JsonWriter writeArrayField(String fieldName, Iterable<T> array, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array field.

      This API will begin by writing the field name and start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      If the passed array is null a JSON null field will be written. If a null field shouldn't be written use writeArrayField(String, Iterable, boolean, BiConsumer) and pass false for writeNull.

      Combines writeFieldName(String) and writeArray(Iterable, BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The array element type.
      Parameters:
      fieldName - The field name.
      array - The array being written.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeArrayField

      public final <T> JsonWriter writeArrayField(String fieldName, Iterable<T> array, boolean writeNull, BiConsumer<JsonWriter,T> elementWriterFunc)
      Writes a JSON array field.

      This API will begin by writing the field name and start array ([) followed by all elements in the array using the elementWriterFunc and finishing by writing the end array (]).

      writeNull determines whether a JSON null field should be written if array is null.

      Combines writeFieldName(String) and writeArray(Object[], boolean, BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The array element type.
      Parameters:
      fieldName - The field name.
      array - The array being written.
      writeNull - Whether JSON null should be written if array is null.
      elementWriterFunc - The function that writes each element of the array.
      Returns:
      The updated JsonWriter object.
    • writeMapField

      public final <T> JsonWriter writeMapField(String fieldName, Map<String,T> map, BiConsumer<JsonWriter,T> valueWriterFunc)
      Writes a JSON map field.

      This API will begin by writing the field name and start object (&#123;) followed by key-value fields in the map using the valueWriterFunc and finishing by writing the end object (&#125;).

      If the passed map is null a JSON null field will be written. If a null field shouldn't be written use writeMapField(String, Map, boolean, BiConsumer) and pass false for writeNull.

      Combines writeFieldName(String) and writeMap(Map, BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The value element type.
      Parameters:
      fieldName - The field name.
      map - The map being written.
      valueWriterFunc - The function that writes each value of the map.
      Returns:
      The updated JsonWriter object.
    • writeMapField

      public final <T> JsonWriter writeMapField(String fieldName, Map<String,T> map, boolean writeNull, BiConsumer<JsonWriter,T> valueWriterFunc)
      Writes a JSON map field.

      This API will begin by writing the field name and start object (&#123;) followed by key-value fields in the map using the valueWriterFunc and finishing by writing the end object (&#125;).

      writeNull determines whether a JSON null field should be written if map is null.

      Combines writeFieldName(String) and writeMap(Map, boolean, BiConsumer) to simplify adding a key-value to a JSON object.

      Type Parameters:
      T - The value element type.
      Parameters:
      fieldName - The field name.
      map - The map being written.
      writeNull - Whether JSON null should be written if map is null.
      valueWriterFunc - The function that writes each value of the map.
      Returns:
      The updated JsonWriter object.
    • writeJsonField

      public final JsonWriter writeJsonField(String fieldName, JsonSerializable<?> value, boolean writeNull)
      Writes a JsonSerializable field.

      Combines writeFieldName(String) and writeJson(JsonSerializable) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - JsonSerializable object to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeBinaryField

      public abstract JsonWriter writeBinaryField(String fieldName, byte[] value)
      Writes a JSON binary field.

      Combines writeFieldName(String) and writeBinary(byte[]) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeBinaryField(String, byte[], boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Binary value to write.
      Returns:
      The updated JsonWriter object.
    • writeBinaryField

      public final JsonWriter writeBinaryField(String fieldName, byte[] value, boolean writeNull)
      Writes a JSON binary field.

      Combines writeFieldName(String) and writeBinary(byte[]) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Binary value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeBooleanField

      public abstract JsonWriter writeBooleanField(String fieldName, boolean value)
      Writes a JSON boolean field.

      Combines writeFieldName(String) and writeBoolean(boolean) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - boolean value to write.
      Returns:
      The updated JsonWriter object.
    • writeBooleanField

      public final JsonWriter writeBooleanField(String fieldName, Boolean value)
      Writes a nullable JSON boolean field.

      Combines writeFieldName(String) and writeBoolean(Boolean) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeBooleanField(String, Boolean, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Boolean value to write.
      Returns:
      The updated JsonWriter object.
    • writeBooleanField

      public final JsonWriter writeBooleanField(String fieldName, Boolean value, boolean writeNull)
      Writes a nullable JSON boolean field.

      Combines writeFieldName(String) and writeBoolean(Boolean) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Boolean value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeDoubleField

      public abstract JsonWriter writeDoubleField(String fieldName, double value)
      Writes a JSON double field.

      Combines writeFieldName(String) and writeDouble(double) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - double value to write.
      Returns:
      The updated JsonWriter object.
    • writeDoubleField

      public final JsonWriter writeDoubleField(String fieldName, Double value)
      Writes a nullable JSON double field.

      Combines writeFieldName(String) and writeDouble(Double) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeDoubleField(String, Double, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Double value to write.
      Returns:
      The updated JsonWriter object.
    • writeDoubleField

      public final JsonWriter writeDoubleField(String fieldName, Double value, boolean writeNull)
      Writes a nullable JSON double field.

      Combines writeFieldName(String) and writeDouble(Double) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Double value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeFloatField

      public abstract JsonWriter writeFloatField(String fieldName, float value)
      Writes a JSON float field.

      Combines writeFieldName(String) and writeFloat(float) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - float value to write.
      Returns:
      The updated JsonWriter object.
    • writeFloatField

      public final JsonWriter writeFloatField(String fieldName, Float value)
      Writes a nullable JSON float field.

      Combines writeFieldName(String) and writeFloat(Float) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeFloatField(String, Float, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Float value to write.
      Returns:
      The updated JsonWriter object.
    • writeFloatField

      public final JsonWriter writeFloatField(String fieldName, Float value, boolean writeNull)
      Writes a nullable JSON float field.

      Combines writeFieldName(String) and writeFloat(Float) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Float value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeIntField

      public abstract JsonWriter writeIntField(String fieldName, int value)
      Writes a JSON int field.

      Combines writeFieldName(String) and writeInt(int) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - int value to write.
      Returns:
      The updated JsonWriter object.
    • writeIntegerField

      public final JsonWriter writeIntegerField(String fieldName, Integer value)
      Writes a nullable JSON int field.

      Combines writeFieldName(String) and writeInteger(Integer) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeIntegerField(String, Integer, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Integer value to write.
      Returns:
      The updated JsonWriter object.
    • writeIntegerField

      public final JsonWriter writeIntegerField(String fieldName, Integer value, boolean writeNull)
      Writes a nullable JSON int field.

      Combines writeFieldName(String) and writeInteger(Integer) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Integer value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeLongField

      public abstract JsonWriter writeLongField(String fieldName, long value)
      Writes a JSON long field.

      Combines writeFieldName(String) and writeLong(long) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - long value to write.
      Returns:
      The updated JsonWriter object.
    • writeLongField

      public final JsonWriter writeLongField(String fieldName, Long value)
      Writes a nullable JSON long field.

      Combines writeFieldName(String) and writeLong(Long) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeLongField(String, Long, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - Long value to write.
      Returns:
      The updated JsonWriter object.
    • writeLongField

      public final JsonWriter writeLongField(String fieldName, Long value, boolean writeNull)
      Writes a nullable JSON long field.

      Combines writeFieldName(String) and writeLong(Long) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - Long value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeNullField

      public abstract JsonWriter writeNullField(String fieldName)
      Writes a JSON null field ("fieldName":null).

      Combines writeFieldName(String) and writeNull() to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      Returns:
      The updated JsonWriter object.
    • writeStringField

      public abstract JsonWriter writeStringField(String fieldName, String value)
      Writes a JSON String field.

      Combines writeFieldName(String) and writeString(String) to simplify adding a key-value to a JSON object.

      A value is always written no matter whether value is null, if null shouldn't be written this API call must be null guarded. Or, use writeStringField(String, String, boolean) to indicate whether null should be written.

      Parameters:
      fieldName - The field name.
      value - String value to write.
      Returns:
      The updated JsonWriter object.
    • writeStringField

      public final JsonWriter writeStringField(String fieldName, String value, boolean writeNull)
      Writes a JSON String field.

      Combines writeFieldName(String) and writeString(String) to simplify adding a key-value to a JSON object.

      If writeNull is false and value is null neither a field name or a field value will be written, effectively treating the call as a no-op.

      Parameters:
      fieldName - The field name.
      value - String value to write.
      writeNull - Whether a null field should be written.
      Returns:
      The updated JsonWriter object, or if writeNull is false and value is null the unmodified JsonWriter.
    • writeRawField

      public abstract JsonWriter writeRawField(String fieldName, String value)
      Writes the passed field literally without any additional handling.

      Use this API when writing a String value that is already properly formatted JSON, such as a JSON string ("\"string\""), number ("42", "42.0"), boolean ("true", "false"), null ("null"), array ("[\"string\", \"array\"]"), or object ({"\"field\":\"value\""}).

      Combines writeFieldName(String) and writeRawValue(String) to simplify adding a key-value to a JSON object.

      Parameters:
      fieldName - The field name.
      value - The raw JSON value to write.
      Returns:
      The updated JsonWriter object.
    • writeUntypedField

      public JsonWriter writeUntypedField(String fieldName, Object value)
      Writes the unknown type value field.

      The following is how each value is handled (in this order):

      Parameters:
      fieldName - The field name.
      value - The value to write.
      Returns:
      The updated JsonWriter object.
    • writeUntyped

      public JsonWriter writeUntyped(Object value)
      Writes the unknown type value.

      The following is how each value is handled (in this order):

      Parameters:
      value - The value to write.
      Returns:
      The updated JsonWriter object.