Comments (9)
Hi @sabrinawilske, thanks for filing this issue. It sounds like an earlier version of Gson is still being used, as Gson 2.7 introduced the ability to use @JsonAdapter
s of types other than TypeAdapter
and TypeAdapterFactory
.
- If you're using Maven, could you paste the result of running
mvn dependency:tree
from your project's root directory? - If you're using Gradle, could you paste the result of running
./gradlew :projectName:dependencies
, whereprojectName
is the name of your Gradle module (or omit this entirely and do./gradlew :dependencies
if you're using the root module).
Thanks.
from clarifai-java.
Hi, the output of dependency:tree seems to suggest that I am using gson2.8
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ InstagramHarvester ---
[INFO] InstagramHarvester:InstagramHarvester:jar:0.0.1-SNAPSHOT
[INFO] +- com.google.code.gson:gson:jar:2.8.0:compile
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.apache.poi:poi:jar:3.13:compile
[INFO] | \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.13:compile
[INFO] | \- org.apache.poi:poi-ooxml-schemas:jar:3.13:compile
[INFO] | \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] | \- stax:stax-api:jar:1.0.1:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.4.7:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | +- org.apache.httpcomponents:httpasyncclient:jar:4.0.2:compile
[INFO] | | \- org.apache.httpcomponents:httpcore-nio:jar:4.3.2:compile
[INFO] | +- org.apache.httpcomponents:httpmime:jar:4.3.6:compile
[INFO] | \- org.json:json:jar:20140107:compile
[INFO] \- com.clarifai.clarifai-api2:core:jar:2.2.1:compile
[INFO] \- com.squareup.okhttp3:okhttp:jar:3.4.1:compile
[INFO] \- com.squareup.okio:okio:jar:1.9.0:compile
from clarifai-java.
@sabrinawilske Hm, it certainly should be using Gson 2.8 based on that dependency tree. I suspect it still might not be because the text from the exception you're showing was removed in Gson 2.7 (2.7 and 2.8.0's exception, which you can see here, also mentions that JsonSerializer
and JsonDeserializer
, which we use in the client, are valid, while 2.6.2 and below use the text that you encountered).
Regardless, because we're seeing a lot of people ending up with an earlier Gson version at runtime (either on purpose or because of other transitive dependencies), we've reverted back to using TypeAdapterFactory
, which I'm hoping will solve this problem as well. Can you try updating your Clarifai API client version from 2.2.1
to 2.2.2
and see if that works?
Sorry I can't really identify the underlying issue at hand, but let me know if the update resolves this.
from clarifai-java.
Thanks Kevin.
I tried the same minimal code with clarifai 2.2.2 but I get the following errors (tried with gson 2.8.0, 2.7. and 2.6.2, all result in the same error)
java.lang.IllegalArgumentException: GSON cannot serialize clarifai2.dto.input.ClarifaiInput
Here is part of the full message:
Exception in thread "main" java.lang.IllegalArgumentException: GSON cannot serialize clarifai2.dto.input.ClarifaiInput
at com.google.gson.Gson.getDelegateAdapter(Gson.java:437)
at clarifai2.internal.JSONAdapterFactory.passthroughAdapter(JSONAdapterFactory.java:77)
at clarifai2.internal.JSONAdapterFactory.buildAdapter(JSONAdapterFactory.java:73)
at clarifai2.internal.JSONAdapterFactory.create(JSONAdapterFactory.java:69)
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.create(JsonAdapterAnnotationTypeAdapterFactory.java:46)
at com.google.gson.Gson.getAdapter(Gson.java:358)
at com.google.gson.Gson.getAdapter(Gson.java:447)
at clarifai2.internal.AutoValueTypeAdapterFactory.create(AutoValueTypeAdapterFactory.java:35)
at com.google.gson.Gson.getAdapter(Gson.java:358)
at com.google.gson.Gson.toJson(Gson.java:587)
at com.google.gson.Gson.toJsonTree(Gson.java:488)
at com.google.gson.Gson.toJsonTree(Gson.java:467)
at clarifai2.api.request.model.PredictRequest$1$1.call(PredictRequest.java:61)
at clarifai2.api.request.model.PredictRequest$1$1.call(PredictRequest.java:59)
at clarifai2.internal.JSONArrayBuilder.addAll(JSONArrayBuilder.java:60)
at clarifai2.api.request.model.PredictRequest$1.httpRequest(PredictRequest.java:59)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:256)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
at com.tnsglobal.instagram.clarifai.ClarifaiRetriever_v2.processOneURL(ClarifaiRetriever_v2.java:123)
at com.tnsglobal.instagram.clarifai.ClarifaiRetriever_v2.main(ClarifaiRetriever_v2.java:96)
Exception in thread "pool-1-thread-1" java.lang.IllegalArgumentException: GSON cannot serialize clarifai2.dto.ClarifaiStatus
at com.google.gson.Gson.getDelegateAdapter(Gson.java:437)
[....]
Exception in thread "pool-1-thread-7" java.lang.IllegalArgumentException: GSON cannot serialize clarifai2.dto.ClarifaiStatus
at com.google.gson.Gson.getDelegateAdapter(Gson.java:437)
at clarifai2.internal.JSONAdapterFactory.passthroughAdapter(JSONAdapterFactory.java:77)
at clarifai2.internal.JSONAdapterFactory.buildAdapter(JSONAdapterFactory.java:73)
at clarifai2.internal.JSONAdapterFactory.create(JSONAdapterFactory.java:69)
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.create(JsonAdapterAnnotationTypeAdapterFactory.java:46)
at com.google.gson.Gson.getAdapter(Gson.java:358)
at com.google.gson.Gson.fromJson(Gson.java:804)
at com.google.gson.Gson.fromJson(Gson.java:870)
at com.google.gson.Gson.fromJson(Gson.java:843)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:275)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
at clarifai2.dto.model.DefaultModels.update(DefaultModels.java:52)
at clarifai2.dto.model.DefaultModels.access$000(DefaultModels.java:10)
at clarifai2.dto.model.DefaultModels$1.run(DefaultModels.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
from clarifai-java.
Ah, that exception seems to be caused by some stuff I just added in 2.2.2 related to Gson. I just guarded against it (not sure why I'm not running into it on my end, but your stacktraces indicate what's going on pretty clearly) and rolled a new release for it, so can you try out 2.2.3? Sorry for the inconvenience, and thanks for providing useful debugging info!
from clarifai-java.
Hi Kevin,
thanks for your update!
I tried 2.2.3 but now get a new error :-(
Exception in thread "pool-1-thread-1" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT
at com.google.gson.Gson.fromJson(Gson.java:817)
at com.google.gson.Gson.fromJson(Gson.java:870)
at com.google.gson.Gson.fromJson(Gson.java:843)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.ModelVersion$Adapter$1.deserialize(ModelVersion.java:42)
at clarifai2.dto.model.ModelVersion$Adapter$1.deserialize(ModelVersion.java:31)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.Gson.fromJson(Gson.java:805)
at com.google.gson.Gson.fromJson(Gson.java:870)
at com.google.gson.Gson.fromJson(Gson.java:843)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:211)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:197)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.Gson.fromJson(Gson.java:805)
at com.google.gson.Gson.fromJson(Gson.java:870)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:34)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:32)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:285)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
at clarifai2.dto.model.DefaultModels.update(DefaultModels.java:52)
at clarifai2.dto.model.DefaultModels.access$000(DefaultModels.java:10)
at clarifai2.dto.model.DefaultModels$1.run(DefaultModels.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT
at com.google.gson.internal.bind.JsonTreeReader.nextString(JsonTreeReader.java:154)
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.read(TypeAdapters.java:741)
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.read(TypeAdapters.java:717)
at com.google.gson.Gson.fromJson(Gson.java:805)
... 25 more
[repeats 6 more times for different pool-1-thread-N]
from clarifai-java.
Hi, sorry for the frustrations with the library. As I've been testing this library mainly with Gradle up until this point, I thought it might be worth putting together a minimal test-case with Maven to ensure that nothing build-tool-specific is causing any issues. I've created a minimal example, zero-dependency example that'll run on any machine with JDK 6 and pushed it to a public repo. It uses version 2.2.3 of this API client: https://github.com/kevinmost/clarifai-java-starter
I can verify that this sample works for the operation you specified in your original post (predicting with one image URL via the general model). Is this sample broken for you as well?
from clarifai-java.
@sabrinawilske Are you still getting this error?
from clarifai-java.
Closing this because I can't replicate.
from clarifai-java.
Related Issues (20)
- IOException in ClarifaiRequester HOT 4
- No way to shutdown client? HOT 2
- Failed to invoke clarifai2.dto.ClarifaiStatus() with no args HOT 12
- Cannot get customized language for prediction API HOT 2
- i am trying to robot with clarifai API i need help HOT 1
- Can't instantiate class ColorOutputInfo HOT 4
- README.md contains broken link HOT 1
- Exception in thread "pool-1-thread-1" java.lang.NullPointerException: Null concepts HOT 6
- Clarifai with offline images HOT 3
- .getDefaultModels() does not have celebrity model HOT 2
- NullPointer Exception HOT 2
- testRecognizeMultiple() fails out of the box HOT 1
- Empty payload for additional video inputs when bulk processing HOT 1
- Problem using the library with Android HOT 1
- Failed to invoke clarifai2.dto.model.output_info.UnknownOutputInfo() with no args HOT 2
- [BUG] exception thrown for requests to NSFW model
- Whatsapp coud to +201007820419
- IOException from running sample HOT 7
- Add support for select classes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clarifai-java.