我仍然无法使用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);
}
}