@Override
  public Object decode(Response response, Type type) throws IOException, DecodeException {
    if (response.status() == 404 || response.status() == 204)
      if (JSONObject.class.isAssignableFrom((Class<?>) type))
        return new JSONObject();
      else if (JSONArray.class.isAssignableFrom((Class<?>) type))
        return new JSONArray();
      else if (String.class.equals(type))
        return null;
      else
        throw new DecodeException(response.status(),
            format("%s is not a type supported by this decoder.", type), response.request());
    if (response.body() == null)
      return null;
    try (Reader reader = response.body().asReader(response.charset())) {
      Reader bodyReader = (reader.markSupported()) ? reader : new BufferedReader(reader);
      bodyReader.mark(1);
      if (bodyReader.read() == -1) {
        return null; // Empty body
      }
      bodyReader.reset();
      return decodeBody(response, type, bodyReader);
    } catch (JSONException jsonException) {
      if (jsonException.getCause() != null && jsonException.getCause() instanceof IOException) {
        throw (IOException) jsonException.getCause();
      }
      throw new DecodeException(response.status(), jsonException.getMessage(), response.request(),
          jsonException);
    }
  }
@Test
  void unknownTypeThrowsDecodeException() throws IOException {
    String json = "[{\"a\":\"b\",\"c\":1},123]";
    Response response = Response.builder()
        .status(200)
        .reason("OK")
        .headers(Collections.emptyMap())
        .body(json, UTF_8)
        .request(request)
        .build();
    Exception exception = assertThrows(DecodeException.class,
        () -> new JsonDecoder().decode(response, Clock.class));
    assertThat(exception.getMessage())
        .isEqualTo("class java.time.Clock is not a type supported by this decoder.");
  }