Trying POST without any organ using Retrofit with GSON parsing error

I integrate with the REST API, so I use Retrofit. I need to click the URL:

Http: // {{server}} / API / v1 / material / {{ID}} / deactivate

I created an interface that implements the API:

@PUT("/api/v1/stuff/{id}/deactivate")
String deactivate(@Path("id") String id);

The problem is that I call the method that it fails with the following stack trace:

E/AndroidRuntime( 3046): Caused by: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 15  
E/AndroidRuntime( 3046):        at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:67)    
E/AndroidRuntime( 3046):        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:393) 
E/AndroidRuntime( 3046):        ... 11 more 
E/AndroidRuntime( 3046): Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 15   
E/AndroidRuntime( 3046):        at com.google.gson.Gson.assertFullConsumption(Gson.java:779) 
E/AndroidRuntime( 3046):        at com.google.gson.Gson.fromJson(Gson.java:769)   
E/AndroidRuntime( 3046):  at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:63) 
E/AndroidRuntime( 3046):        ... 12 more 
E/AndroidRuntime( 3046): Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 15 
E/AndroidRuntime( 3046):        at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505) 
E/AndroidRuntime( 3046):        at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386) 
E/AndroidRuntime( 3046):        at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531) 
E/AndroidRuntime( 3046):        at com.google.gson.stream.JsonReader.peek(JsonReader.java:414) 
E/AndroidRuntime( 3046):        at com.google.gson.Gson.assertFullConsumption(Gson.java:775) 
E/AndroidRuntime( 3046):        ... 14 more

I believe that this is due to the fact that I do not publish anything in the body. What is the best way to get around this?

Note. I have successfully used POSTMan to call the API.

+3
source share
2 answers

Enabling full debugging with:

setLogLevel(RestAdapter.LogLevel.FULL)

, Gson - JSON, . "" , .

. , , .

+3

. :

@POST("/item/{id}")
void postItem(@Path("id") int id, Callback<String> callback);

okhttp. :

@POST("/item/{id}")
void postItem(@Path("id") int id, @Body String body, Callback<String> callback);

:

service.postItem(id, "", callback);
0

All Articles