2017-05-23 45 views
0

不太清楚爲什麼會這樣......請看這個截圖: oauth2_token_obtained_debug春季安全的oauth2令牌是空

在GsonHttpMessageConverter.java:197,方法writeInternal,我可以看到的OAuth2令牌已創建正在編組。但是,我得到的響應是一個空的json主體{}。數據庫在oauth_access_token表中具有正確的標記。我只是沒有得到它的答覆。

我在網上找到了一個類似的問題,但沒有回答這個問題: https://github.com/royclarkson/spring-rest-service-oauth/issues/49

看來,GSON沒有寫入到輸出流。有任何想法嗎?

回答

0

我仍然無法使用guth與OAuth2,響應正文爲空。

我所做的就是從我的依賴中刪除gson並添加Jackson 2.8.8。它現在起作用了,我得到了適當的Json響應。

我不知道爲什麼gson不做任何事情。不工作的代碼是GsonHttpMessageConverter:197

@Override 
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage) 
     throws IOException, HttpMessageNotWritableException { 

    Charset charset = getCharset(outputMessage.getHeaders()); 
    OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset); 
    try { 
     if (this.jsonPrefix != null) { 
      writer.append(this.jsonPrefix); 
     } 
     if (type != null) { 
      this.gson.toJson(o, type, writer); // <-- this line DOES NOT write "o" of type DefaultOAuth2AccessToken to the OutputStreamWriter 
     } 
     else { 
      this.gson.toJson(o, writer); 
     } 
     writer.close(); 
    } 
    catch (JsonIOException ex) { 
     throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); 
    } 
}