Class JsonBoolean

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

public final class JsonBoolean extends JsonElement
Model representing a JSON boolean value.
  • Method Details

    • getInstance

      public static JsonBoolean getInstance(boolean value)
      Gets the instance of JsonBoolean for the specified boolean value.
      Parameters:
      value - The boolean value for which to obtain the JsonBoolean instance.
      Returns:
      The instance of JsonBoolean representing the specified boolean value.
    • getValue

      public boolean getValue()
      Returns boolean value from a JsonBoolean object.
      Returns:
      The boolean value.
    • isBoolean

      public boolean isBoolean()
      Identifies if an object is of type JsonBoolean.
      Overrides:
      isBoolean in class JsonElement
      Returns:
      boolean of whether this JsonElement object is of type JsonBoolean.
    • 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 JsonBoolean fromJson(JsonReader jsonReader) throws IOException
      Deserializes a JSON boolean 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.BOOLEAN, an IllegalStateException will be thrown. Otherwise, getInstance(boolean) will be called to return the deserialized JSON boolean.

      Parameters:
      jsonReader - The JsonReader to deserialize from.
      Returns:
      The deserialized JSON boolean.
      Throws:
      IOException - If an error occurs while deserializing the JSON boolean.
      IllegalStateException - If the current token is not JsonToken.BOOLEAN.
    • 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.