Retrofit: is there any easy way to set lenient mode for json converter in retrofit 2.0 beta4?

Created on 14 Mar 2016  路  4Comments  路  Source: square/retrofit

Hello, I am getting an MalformedJsonException when I am using retrofit2.

Here is my originally posted question:
http://stackoverflow.com/questions/35984898/retrofit2-0-gets-malformedjsonexception-while-the-json-seems-correct

since the stacktrace said:

 com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $

I am wondering how to set Lenient mode for json conveter?

What I have found in the following seems not valid for retrofit 2
http://stackoverflow.com/questions/27485346/malformedjsonexception-with-retrofit-api

Could you please help?

Most helpful comment

Gson gson = new GsonBuilder()
    .setLenient()
    .build();
// ...
.addConverterFactory(GsonConverterFactory.create(gson))

All 4 comments

Gson gson = new GsonBuilder()
    .setLenient()
    .build();
// ...
.addConverterFactory(GsonConverterFactory.create(gson))

Thanks however it's create() not build()
Gson gson = new GsonBuilder() .setLenient() .create();

I had added this line
Gson gson = new GsonBuilder() .setLenient() .create(); but still gives me the same error.

You can follow this solution: https://readyandroid.wordpress.com/error-use-jsonreader-setlenienttrue-to-accept-malformed-json-at-line-1-column-1-path/
Still, this doesn't work for you then try to do change in your API at server end because something wrong happens there.
As for me my sign up API doesn't work and was giving this same error I was thinking might be I am sending image as a multipart request that's why it is not working but where my edit profile API was working so I was little surprise of this then I made a clone of my Edit Profile API and renamed it to sign up and do the whatever required changes for the parameters and it started working. I don't know what wrong was there. Might be server guy may know what is the real cause of this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bolds07 picture bolds07  路  3Comments

Liberuman picture Liberuman  路  3Comments

colintheshots picture colintheshots  路  3Comments

ramonmoraes8080 picture ramonmoraes8080  路  3Comments

kkunsue picture kkunsue  路  3Comments