Share via


JsonString Class

public final class JsonString
extends JsonElement

Class representing the JSON string type

Constructor Summary

Constructor Description
JsonString(String value)

Constructor used to explicitly set the string value of the JsonString object.

Method Summary

Modifier and Type Method and Description
static JsonString fromJson(JsonReader jsonReader)

Deserializes a JSON string from a JsonReader.

String getValue()

Gets the string value of this JsonString object.

boolean isString()

Indicates whether the element is a string.

JsonWriter toJson(JsonWriter jsonWriter)
String toJsonString()

Methods inherited from JsonElement

Methods inherited from java.lang.Object

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

fromJson

public static JsonString fromJson(JsonReader jsonReader)

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 nextToken() will be called to begin reading.

After ensuring the JsonReader has begun reading, if the current token is not 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.

getValue

public String getValue()

Gets the string value of this JsonString object.

Returns:

the string value of this JsonString object

isString

public boolean isString()

Indicates whether the element is a string.

Overrides:

JsonString.isString()

Returns:

boolean of whether this JsonElement object is of type JsonString.

toJson

public JsonWriter toJson(JsonWriter jsonWriter)

Parameters:

jsonWriter

Throws:

toJsonString

public String toJsonString()

Throws:

Applies to