I just noticed Gson performances are not what I expected and some parsing processes are taking a lot of time. I’m not looking for another solution, my app is quite big and I don’t want to alter its structure with something else like jackson.
My Android app allows the user to stop an http request with the back key. My code abort the request and basically stops the task. The thing is, it needs to wait for the method gson.fromJson(result) to abort the task. That instruction can last for a couple of seconds.
Is there any way to tell the gson object to abort the parsing process?
I am not familiar with GSON but you could close the underlying stream of JSON data (Inpustream) to end the parsing process with an exception, which you could catch. That should work in case the input data can be a Stream. I have just taken a look at the GSON API and the fromJson method takes a Reader parameter, which can be closed.
A bad way could be also to run it in a thread and call thread.stop().