2017-05-23 44 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); 
    } 
}