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