'com.google.api.client.json.jackson2.JacksonFactory' 已弃用.我有哪些选择? [英] 'com.google.api.client.json.jackson2.JacksonFactory' is deprecated. What are my options?

查看:68
本文介绍了'com.google.api.client.json.jackson2.JacksonFactory' 已弃用.我有哪些选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在遵循 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();

这篇关于'com.google.api.client.json.jackson2.JacksonFactory' 已弃用.我有哪些选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆