Class JsonNull

java.lang.Object
com.azure.json.models.JsonElement
com.azure.json.models.JsonNull
All Implemented Interfaces:
JsonSerializable<JsonElement>

public final class JsonNull extends JsonElement
Model representing a JSON null value.
  • Method Details

    • getInstance

      public static JsonNull getInstance()
      Gets the instance of the JsonNull class.
      Returns:
      The JsonNull instance.
    • isNull

      public boolean isNull()
      Identifies if a JsonElement is of type JsonNull.
      Overrides:
      isNull in class JsonElement
      Returns:
      A boolean value of whether a JsonElement is null.
    • toJson

      public JsonWriter toJson(JsonWriter jsonWriter) throws IOException
      Description copied from interface: JsonSerializable
      Writes the object to the passed JsonWriter.

      The contract for writing JSON to JsonWriter is that the object being written will handle opening and closing its own JSON object. So, for objects calling out to other JsonSerializable objects for serialization, they'll write the field name only then pass the JsonWriter to the other JsonSerializable object. This way objects writing JSON will be self-encapsulated for writing properly formatted JSON.

      Parameters:
      jsonWriter - Where the object's JSON will be written.
      Returns:
      The JsonWriter where the JSON was written.
      Throws:
      IOException - If the object fails to be written to the jsonWriter.
    • fromJson

      public static JsonNull fromJson(JsonReader jsonReader) throws IOException
      Deserializes a JSON null from a JsonReader.

      If the JsonReader's current token is null, it is assumed the JsonReader hasn't begun reading and JsonReader.nextToken() will be called to begin reading.

      After ensuring the JsonReader has begun reading, if the current token is not JsonToken.NULL, an IllegalStateException will be thrown. Otherwise, getInstance() will be called to return the deserialized JSON null.

      Parameters:
      jsonReader - The JsonReader to deserialize from.
      Returns:
      The deserialized JSON null.
      Throws:
      IOException - If an error occurs while deserializing the JSON null.
      IllegalStateException - If the current token is not JsonToken.NULL.
    • toJsonString

      public String toJsonString() throws IOException
      Description copied from interface: JsonSerializable
      Convenience method for writing the JsonSerializable to a JSON string.
      Returns:
      The JSON string representing the object.
      Throws:
      IOException - If the object fails to be written as a JSON string.