11

Am trying to use the GsonFactory class in my app:

StudentApi.Builder builder = new StudentApi.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), null);

but it says cannot resolve symbol 'GsonFactory'

I have the import in my class

import com.google.api.client.json.gson.GsonFactory;

but gson couldn't be resolved so I tried Alt-Enter - Find jar on web but the library couldn't be found.

I have this in my build.gradle dependencies:

dependencies {
   ...
   compile 'com.google.code.gson:gson:2.3'
   compile 'com.google.api-client:google-api-client-android:1.19.0'
}

I can confirm that this class does exist.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
  • You can also use JacksonFactory if possible. http://stackoverflow.com/questions/17231722/com-google-api-client-json-jackson-jacksonfactory-missing-in-google-drive-examp – user2872177 Sep 30 '15 at 19:44

5 Answers5

27

You need to use this library:

compile 'com.google.http-client:google-http-client-gson:1.19.0'
BrendanBenting
  • 571
  • 6
  • 8
  • You can also use JacksonFactory() in lieu of GsonFactory for those API builders if there is some trouble with the dependency. – BrendanBenting May 09 '15 at 08:29
  • One more comment: For some reason if using the maven dependency doesn't download the Gson library -- you can just include the library manually. http://central.maven.org/maven2/com/google/api-client/google-api-client-gson/1.19.0/google-api-client-gson-1.19.0.jar – BrendanBenting May 09 '15 at 09:39
9

GsonFactory is from the older version.

Now, you should use JacksonFactory.getDefaultInstance() instead.

Import it like this import com.google.api.client.json.jackson2.JacksonFactory;

4

As of 2022, GsonFactory is back and JacksonFactory is deprecated. Replace JacksonFactory with GsonFactory.getDefaultInstance().

In Gradle: use

implementation 'com.google.http-client:google-http-client-gson:1.41.0'
1

In your gradle.build you need to add:

compile ('com.google.http-client:google-http-client-gson:1.19.0') {
    exclude module: 'httpclient'
}

after

compile('com.google.http-client:google-http-client-android:1.19.0') {
    exclude(group: 'com.google.android', module: 'android')
}

After doing so, you will be able to use:

com.google.api.client.json.gson.GsonFactory()
Guildenstern70
  • 1,715
  • 18
  • 18
0

this object is only in older versions of the google-http-client try whit the 1.9.0-beta version

compile 'com.google.http-client:google-http-client-android:1.9.0-beta'
David Chavez
  • 617
  • 3
  • 17