Cannot resolve import com.google.api.client.json.gson.GsonFactory
Asked Answered
L

5

12

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.

Longhand answered 25/4, 2015 at 7:18 Comment(1)
You can also use JacksonFactory if possible. #17232222Booklet
S
28

You need to use this library:

compile 'com.google.http-client:google-http-client-gson:1.19.0'
Skindeep answered 9/5, 2015 at 8:21 Comment(2)
You can also use JacksonFactory() in lieu of GsonFactory for those API builders if there is some trouble with the dependency.Skindeep
One more comment: For some reason if using the maven dependency doesn't download the Gson library -- you can just include the library manually. central.maven.org/maven2/com/google/api-client/…Skindeep
N
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;

Nuno answered 27/7, 2018 at 13:7 Comment(0)
B
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'
Barring answered 9/3, 2022 at 8:53 Comment(0)
H
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()
Highgrade answered 12/8, 2015 at 11:5 Comment(0)
A
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'
Artis answered 16/9, 2015 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.