javajacksongmailgmail-apijackson2

'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?


Solution

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