Class JsonString
- All Implemented Interfaces:
JsonSerializable<JsonElement>
-
Constructor Summary
ConstructorsConstructorDescriptionJsonString(String value) Constructor used to explicitly set the string value of the JsonString object. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonStringfromJson(JsonReader jsonReader) Deserializes a JSON string from a JsonReader.getValue()Gets the string value of this JsonString object.booleanisString()Indicates whether the element is a string.toJson(JsonWriter jsonWriter) Writes the object to the passedJsonWriter.Convenience method for writing theJsonSerializableto a JSON string.Methods inherited from class com.azure.json.models.JsonElement
asArray, asBoolean, asNull, asNumber, asObject, asString, isArray, isBoolean, isNull, isNumber, isObjectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.json.JsonSerializable
toJson, toJson, toJsonBytes
-
Constructor Details
-
JsonString
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
Gets the string value of this JsonString object.- Returns:
- the string value of this JsonString object
-
isString
public boolean isString()Description copied from class:JsonElementIndicates whether the element is a string.- Overrides:
isStringin classJsonElement- Returns:
- boolean of whether this JsonElement object is of type JsonString.
-
toJson
Description copied from interface:JsonSerializableWrites the object to the passedJsonWriter.The contract for writing JSON to
JsonWriteris that the object being written will handle opening and closing its own JSON object. So, for objects calling out to otherJsonSerializableobjects for serialization, they'll write the field name only then pass theJsonWriterto the otherJsonSerializableobject. 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
JsonWriterwhere the JSON was written. - Throws:
IOException- If the object fails to be written to thejsonWriter.
-
fromJson
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, anIllegalStateExceptionwill 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 notJsonToken.STRING.
-
toJsonString
Description copied from interface:JsonSerializableConvenience method for writing theJsonSerializableto a JSON string.- Returns:
- The JSON string representing the object.
- Throws:
IOException- If the object fails to be written as a JSON string.
-