Retrofit: Retrofit 2 does not allow Call without type and is not able to map empty body with Jackson

Created on 28 Oct 2015  路  2Comments  路  Source: square/retrofit

If I understand it correctly Retrofit does not allow using Call without types i.e.:

@DELETE(PATH_COLLECTION_CARD)
Call deleteCard(@Path("id") String collectionId, @Path("card") String cardId);

This results in: Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call or Call

The rationale for this being "All HTTP calls have a response therefore we force you to acknowledge it in your method signature." according to @JakeWharton in this issue.

I'm encountering APIs that returns an empty body but I would still like to use Call for the other features it provides ( execute vs enqueue etc..). My workaround was to declare an EmptyData object like so:

@DELETE(PATH_COLLECTION_CARD)
Call<EmptyData> deleteCard(@Path("id") String collectionId, @Path("card") String cardId);

However, because the body is completely empty Jackson now throws this exception:
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

Wouldn't it make sense to allow Calls without types in this case?

Most helpful comment

Did you try --

@DELETE(PATH_COLLECTION_CARD)
Call<Void> deleteCard(@Path("id") String collectionId, @Path("card") String cardId);

Top of the beta2 change list -- https://github.com/square/retrofit/blob/master/CHANGELOG.md

All 2 comments

Did you try --

@DELETE(PATH_COLLECTION_CARD)
Call<Void> deleteCard(@Path("id") String collectionId, @Path("card") String cardId);

Top of the beta2 change list -- https://github.com/square/retrofit/blob/master/CHANGELOG.md

That was exactly what I was looking for. My google-fu failed me in this instance. Thanks. :)

Was this page helpful?
0 / 5 - 0 ratings