@Override
 protected OAuth2AccessToken readInternal(
     Class<? extends OAuth2AccessToken> clazz, HttpInputMessage response)
     throws IOException, HttpMessageNotReadableException {
   MediaType contentType = response.getHeaders().getContentType();
   if (contentType != null && JSON_MEDIA_TYPE.includes(contentType)) {
     try {
       return getSerializationService().deserializeJsonAccessToken(response.getBody());
     } catch (SerializationException e) {
       throw new OAuth2Exception(
           "Error getting the access token, and unable to read the details of the error in the JSON response.",
           e);
     }
   } else {
     // the spec currently says json is required, but facebook, for example, still returns
     // form-encoded.
     MultiValueMap<String, String> map = FORM_MESSAGE_CONVERTER.read(null, response);
     return getSerializationService().deserializeAccessToken(map.toSingleValueMap());
   }
 }
    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
      MediaType contentType = response.getHeaders().getContentType();
      if (contentType != null
          && (response.getStatusCode().value() == 400 || response.getStatusCode().value() == 401)) {
        if (JSON_MEDIA_TYPE.includes(contentType)) {
          try {
            throw getSerializationService().deserializeJsonError(response.getBody());
          } catch (SerializationException e) {
            throw new OAuth2Exception(
                "Error getting the access token, and unable to read the details of the error in the JSON response.",
                e);
          }
        } else if (FORM_MEDIA_TYPE.includes(contentType)) {
          MultiValueMap<String, String> map = FORM_MESSAGE_CONVERTER.read(null, response);
          throw getSerializationService().deserializeError(map.toSingleValueMap());
        }
      }

      super.handleError(response);
    }