'com.google.api.client.json.jackson2.JacksonFactory' 已弃用.我有哪些选择?

2022-01-23 00:00:00 gmail-api gmail java jackson jackson2

在遵循 Gmail API java 快速入门指南时,我遇到了这个代码片段:

While following the Gmail API java quickstart guide I came across this code snippet:

private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

在编辑器中使用它给了我一个警告,它已被弃用.我有哪些选择?

Using it in the editor gave me a warning that it is deprecated. What are my options?

推荐答案

查找JacksonFactory 类的 API 文档.它告诉你该怎么做:

Look up the API documentation of class JacksonFactory. It tells you what to do:

已弃用.
改用 com.google.api.client.json.GsonFactory

Deprecated.
use com.google.api.client.json.GsonFactory instead

查看 类GsonFactory的API文档你看,它的 API 方法与 JacksonFactory 的方法兼容,因为两者都从同一个超类 JsonFactory 扩展而来.(当然,只有它们的内部实现不同.)

Looking into the API documentation of class GsonFactory you see, its API methods are compatible to those of JacksonFactory, since both extend from the same superclass JsonFactory. (Only their internal implementations are different, of course.)

因此,更改代码很简单.只是为了换行

Therefore it is simple to change your code. Just to replace the line

private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

通过

private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();

相关文章