Class JsonString

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

public final class JsonString extends JsonElement
Class representing the JSON string type
  • Constructor Details

    • JsonString

      public JsonString(String value)
      Constructor used to explicitly set the string value of the JsonString object. Adds the starting and ending double quotation marks.
      Parameters:
      value - specifies the text string this JsonString object represents
  • Method Details

    • getValue

      public String getValue()
      Gets the string value of this JsonString object.
      Returns:
      the string value of this JsonString object
    • isString

      public boolean isString()
      Description copied from class: JsonElement
      Indicates whether the element is a string.
      Overrides:
      isString in class JsonElement
      Returns:
      boolean of whether this JsonElement object is of type JsonString.
    • 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 JsonString fromJson(JsonReader jsonReader) throws IOException
      Deserializes a JSON string 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.STRING, an IllegalStateException will be thrown. Otherwise, a JSON string representing the string value will be created and returned.

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