Interface ApiResponse

All Known Implementing Classes:
ErrorResponse, ImageSearchApiResponse, NewsSearchApiResponse, SpellcheckSearchApiResponse, SuggestSearchApiResponse, VideoSearchApiResponse, WebSearchApiResponse

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 Type
    Method
    Description
    static <T extends ApiResponse>
    T
    from(File dataFile, Class<T> clazz)
    Deserializes an API response from a JSON file.
    static <T extends ApiResponse>
    T
    from(Reader dataReader, Class<T> clazz)
    Deserializes an API response from a JSON reader.
    static <T extends ApiResponse>
    T
    from(String dataString, Class<T> clazz)
    Deserializes an API response from a JSON string.
    static <T extends ApiResponse>
    T
    from(@NotNull HttpResponse<String> dataResponse, Class<T> clazz)
    Deserializes an API response from the body of an HTTP response.
    default String
    Serializes the response object to a JSON string.
    default void
    write(File target)
    Writes the response object to a file on the filesystem.
  • Method Details

    • toJson

      default String toJson()
      Serializes the response object to a JSON string.
      Returns:
      a JSON string representation of the response object.
    • write

      default void write(File target)
      Writes the response object to a file on the filesystem.
      Parameters:
      target - the file to write the response object to.
    • from

      static <T extends ApiResponse> T from(File dataFile, Class<T> clazz)
      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 data
      clazz - the API response class to deserialize into
      Returns:
      the deserialized response
    • from

      static <T extends ApiResponse> T from(String dataString, Class<T> clazz)
      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 data
      clazz - the API response class to deserialize into
      Returns:
      the deserialized response
    • from

      static <T extends ApiResponse> T from(Reader dataReader, Class<T> clazz)
      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 data
      clazz - 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 data
      clazz - the API response class to deserialize into
      Returns:
      the deserialized response