Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'com.google.api.client.json.jackson2.JacksonFactory' is deprecated. What are my options?

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?

like image 338
ANWESH MOHAPATRA Avatar asked Feb 17 '21 19:02

ANWESH MOHAPATRA


Video Answer


2 Answers

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

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

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();

by

private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
like image 183
Thomas Fritsch Avatar answered Oct 22 '22 04:10

Thomas Fritsch


The actual class is com.google.api.client.json.**gson.**GsonFactory. The deprecation message is missing ".gson".

like image 1
dashdee Avatar answered Oct 22 '22 02:10

dashdee