Interface ApiResponse
- All Known Implementing Classes:
ErrorResponse,ImageSearchApiResponse,NewsSearchApiResponse,SpellcheckSearchApiResponse,SuggestSearchApiResponse,VideoSearchApiResponse,WebSearchApiResponse
public sealed interface ApiResponse
permits WebSearchApiResponse, ErrorResponse, ImageSearchApiResponse, NewsSearchApiResponse, SpellcheckSearchApiResponse, VideoSearchApiResponse, SuggestSearchApiResponse
Represents a response from the Brave Search API.
Each implementation corresponds to a search vertical (Web, Image, News, Video, Spellcheck, and
Suggest) or to an API error. Responses are deserialized from JSON with the from methods
and serialized back to JSON with toJson() and write(java.io.File).
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ApiResponse>
TDeserializes an API response from a JSON file.static <T extends ApiResponse>
TDeserializes an API response from a JSON reader.static <T extends ApiResponse>
TDeserializes an API response from a JSON string.static <T extends ApiResponse>
Tfrom(@NotNull HttpResponse<String> dataResponse, Class<T> clazz) Deserializes an API response from the body of an HTTP response.default StringtoJson()Serializes the response object to a JSON string.default voidWrites the response object to a file on the filesystem.
-
Method Details
-
toJson
Serializes the response object to a JSON string.- Returns:
- a JSON string representation of the response object.
-
write
Writes the response object to a file on the filesystem.- Parameters:
target- the file to write the response object to.
-
from
Deserializes an API response from a JSON file.- Type Parameters:
T- the type of the API response- Parameters:
dataFile- the file containing the JSON response dataclazz- the API response class to deserialize into- Returns:
- the deserialized response
-
from
Deserializes an API response from a JSON string.- Type Parameters:
T- the type of the API response- Parameters:
dataString- the string containing the JSON response dataclazz- the API response class to deserialize into- Returns:
- the deserialized response
-
from
Deserializes an API response from a JSON reader.- Type Parameters:
T- the type of the API response- Parameters:
dataReader- the reader supplying the JSON response dataclazz- the API response class to deserialize into- Returns:
- the deserialized response
-
from
static <T extends ApiResponse> T from(@NotNull @NotNull HttpResponse<String> dataResponse, Class<T> clazz) Deserializes an API response from the body of an HTTP response.- Type Parameters:
T- the type of the API response- Parameters:
dataResponse- the HTTP response whose body contains the JSON response dataclazz- the API response class to deserialize into- Returns:
- the deserialized response
-