fromJson

inline fun <T> fromJson(json: String): T

Parses the specified JSON string into an object of type T using Gson library.

Return

The parsed object of type T.

Parameters

json

The JSON string to parse.

Throws

JsonSyntaxException

if the JSON is not well-formed or cannot be parsed.


inline fun <T> fromJson(reader: Reader): T

Parses JSON data from a Reader into an object of type T using the Gson library.

Return

The parsed object of type T.

Parameters

reader

The Reader providing the JSON data.

Throws

JsonSyntaxException

if the JSON is not well-formed or cannot be parsed into the specified type.


inline fun <T> fromJson(json: JsonElement): T

Parses the specified JsonElement into an object of type T using Gson library.

Return

The parsed object of type T.

Parameters

json

The JsonElement to parse.

Throws

JsonSyntaxException

if the JSON is not well-formed or cannot be parsed.


inline fun <T> Gson.fromJson(json: String): T

Parses the specified string into an object of type T using Gson library.

Return

The parsed object of type T.

Parameters

json

The json string to parse.

Throws

JsonSyntaxException

if the JSON is not well-formed or cannot be parsed.


inline fun <T> fromJson(json: String, serializer: JsonDeserializer<T>): T

Parses the specified JSON string into an object of type T using Gson library. With additional parameter to add your custom deserializer.

Return

The parsed object of type T.

Parameters

json

The JSON string to parse.

serializer

The JSON deserializer to use for parsing.

Throws

JsonSyntaxException

if the JSON is not well-formed or cannot be parsed.


inline fun <T> Response.fromJson(errorMessage: String = "Response must not be empty."): T

Parses the response body of this Response into an object of type T using Gson.

Return

The parsed object of type T.

Parameters

errorMessage

The error message to use if the response body is empty.

Throws

If the response body is empty.

JsonSyntaxException

If the JSON is not well-formed or cannot be parsed into the specified type.