Class JsonBody
-
- All Implemented Interfaces:
public final class JsonBody extends RequestBody
Represents the body of a network request containing JSON data.
-
-
Field Summary
Fields Modifier and Type Field Description private final JSONObjectjsonObject
-
Constructor Summary
Constructors Constructor Description JsonBody(JSONObject jsonObject, Integer encoding)
-
Method Summary
Modifier and Type Method Description final JSONObjectgetJsonObject()The JSON object to send in the request body. UnitwriteToStream(BufferedSink bufferedSink)Writes the JSON object as a UTF-8 string to the provided BufferedSink. StringgetContentType()Gets the content type for JSON data. BufferedSourcegetSource()Gets a BufferedSource for reading the JSON data. -
-
Constructor Detail
-
JsonBody
JsonBody(JSONObject jsonObject, Integer encoding)
- Parameters:
encoding- The encoding of the JSON data.
-
-
Method Detail
-
getJsonObject
final JSONObject getJsonObject()
The JSON object to send in the request body.
-
writeToStream
Unit writeToStream(BufferedSink bufferedSink)
Writes the JSON object as a UTF-8 string to the provided BufferedSink.
- Parameters:
bufferedSink- The sink to write the JSON data to.
-
getContentType
String getContentType()
Gets the content type for JSON data.
- Returns:
The content type string, typically "application/json".
-
getSource
BufferedSource getSource()
Gets a BufferedSource for reading the JSON data.
- Returns:
A BufferedSource containing the JSON data as a UTF-8 string.
-
-
-
-